+ Reply to Thread
Results 1 to 5 of 5

Pivot Filter as variable in DAX formula

  1. #1
    Registered User
    Join Date
    01-27-2021
    Location
    NY
    MS-Off Ver
    365
    Posts
    8

    Pivot Filter as variable in DAX formula

    I created a pivot table with a bunch of columns. Column A is a date, and Column B is Sales. I placed date in the filter. So I can select a date and filter my output.

    I want to use DAX to find the number of days in the month selected in the filter, to calculate avg sales.

    I can't figure out how to reference the filter in the EOMONTH("var",0). If it's plain excel, I would just refence A3 and get an answer.

    Ideas?

    Thanks

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Pivot Filter as variable in DAX formula

    If you have SELECTEDVALUE available you can use that. Otherwise, you can simply refer to VALUES(DateField) - you'll probably want to wrap that in a HASONEVALUE test to make sure one particular date has been selected - to get the selected date.
    Rory

  3. #3
    Registered User
    Join Date
    01-27-2021
    Location
    NY
    MS-Off Ver
    365
    Posts
    8

    Re: Pivot Filter as variable in DAX formula

    Thanks Rory,

    I tried all three options you gave. The results for SELECTEDVALUE and VALUES was a date vs number of days as in EOMONTH("var",0), so if I select a Febuary date, I get usually 28, but if January I'd get 31.

    HASONEVALUE gave me "TRUE".

    However, as a workaround, I just used DAY(EOMONTH("var",0) in the underlying sheet (new column).
    Last edited by wspivak; 05-11-2023 at 07:06 AM.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Pivot Filter as variable in DAX formula

    You'd use:

    DAY(EOMONTH(VALUES(Datefield),0))

    in the DAX measure

  5. #5
    Registered User
    Join Date
    01-27-2021
    Location
    NY
    MS-Off Ver
    365
    Posts
    8

    Thumbs up Re: Pivot Filter as variable in DAX formula

    That worked, Thanks!!!!!!!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Use a variable to change pivot table filter
    By dweingar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-18-2019, 12:14 PM
  2. Pivot table filter with variable
    By oulouis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2018, 11:15 AM
  3. Problem trying to use variable to filter pivot table.
    By dquigley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2016, 12:07 PM
  4. Macro to filter a pivot whilst looping through filter criteria in a variable list.
    By Alistairm88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2015, 04:25 AM
  5. Filter pivot or other using a variable array
    By YounesB3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-01-2015, 11:08 AM
  6. Pivot Table to Filter using a variable
    By shanegr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-18-2015, 07:34 AM
  7. Automatically filter Pivot Table using a variable
    By ctpoodle in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-10-2013, 02:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1