Forum Discussion

Saskwyt's avatar
Saskwyt
Frequent Visitor
3 years ago
Solved

Use slicer value in Dax Measure

Hi there,

 

Please see attached a basic PBIX model showing a sales table, a budget table and a date table. I'm trying to work out how to adjust the DAX for the measures All_Sales and All_Budget.

 

Sales vs Budget.pbix

 

The measures are currently as follows:

 

All_Sales =

Calculate(

    SUM(Tbl_Sales[Sales]),

        Filter(Date_Table,Date_Table[Date] <= Date(2023,6,30))

    )

 

All_Budget =

Calculate(

    SUM(Tbl_Budget[Budget]),

        Filter(Date_Table,Date_Table[EOM] > Date(2023,6,30))

 

I'm trying to change the DAX so that the "Date(2023,6,30)" is replaced by the value I choose in my Date slicer.

 

Can someone help me achieve this please?

 

Thanks in advance

 

6 Replies

  • mlsx4's avatar
    mlsx4
    Icon for Memorable Member rankMemorable Member

    Hi Saskwyt 

     

    I cannot see the pbix, but you can do:

     

    All_Sales = 
      var _max = maxx(ALLSELECTED('Date_Table'),'Date_Table'[Date])
    RETURN 
      CALCULATE(SUM(Tbl_Sales[Sales], FILTER(ALL('Date_Table'),'Date_Table'[Date]<=_max))

    Same for budget...

  • Saskwyt's avatar
    Saskwyt
    Frequent Visitor

    Hey mlsx4 thanks for the feedback. See below an image of the table I'm trying to achieve - This is what my current Measures are returning. It looks like your suggested solution gives the total up to the date but doesn't show it month by month as shown below:

    Hope that makes more sense!

  • Saskwyt , The function selectedvalue should help in this condition.

    All_Sales =
    Calculate(
        SUM(Tbl_Sales[Sales]),
            Date_Table[Date] <= SELECTEDVALUE(Date_Table[Date])
    )
     
    This should take the sum of sales till the date on slicer.
    • Saskwyt's avatar
      Saskwyt
      Frequent Visitor

      Hi ChiragGarg2512 I can't seem to get this to work...Thank you for your response though 🙂