Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Comparing Two different dates | PowerBI

hi,

I want to compare two different dates from the same tables

 

Example:

Below is my table

MeterdateCost
ADB12-6-202223.45
ADF12-6-202234.56
Storage12-6-202214.56
ADB12-8-202212
ADF12-8-202223.45
Storage12-8-202245.6

 

I want to compare the cost for these two dates such that my output is like this.

 

MeterPreviousCostNewCost
ADB23.4512
ADF34.5623.45

 

I want to compare dates on the dashboard

 

  • Hi Anonymous ,

     

    Create a new table for user to select the previous date via PreviousDate = VALUES('Table'[date])

     

    Then use this measure to get the values of previous date.

    PreviousCost = CALCULATE(SUM('Table'[Cost]),'Table'[date]=SELECTEDVALUE(PreviousDate[date]))
     
    Reault:

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

9 Replies

  • Hi,

    I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

    Those are for creating new measures.

     

     

    Previous cost measure: = 
    VAR _latestdate =
        MAX ( Data[date] )
    VAR _previousdate =
        CALCULATE ( MAX ( Data[date] ), Data[date] < _latestdate )
    VAR _previouscost =
        CALCULATE ( MAX ( Data[Cost] ), Data[date] = _previousdate )
    RETURN
        IF ( HASONEVALUE ( Data[Meter] ), _previouscost )

     

    New cost measure: = 
    VAR _latestdate =
        MAX ( Data[date] )
    VAR _latestcost =
        CALCULATE ( MAX ( Data[Cost] ), Data[date] = _latestdate )
    RETURN
        IF ( HASONEVALUE ( Data[Meter] ), _latestcost )
    
    • Anonymous's avatar
      Anonymous
      Not applicable

      hi Jihwan_Kim , will this also work if I select two different dates from a filter via dashboard?

      • Jihwan_Kim's avatar
        Jihwan_Kim
        Super User

        Hi,

        Thank you for your feedback.

        I cannot know without seeing your data model.

        Please share your sample pbix file's link here, and then I can try to have a look into it.

        Thanks.

  • Anonymous , for meausre you can have

     

    Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

     

    or

     

    Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =calculate( max(Sales[Sales Date]), FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])))))

     

     

    or refer

    Day Intelligence - Last day, last non continous day
    https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c3243d1f9

     

    Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

  • Anonymous's avatar
    Anonymous
    Not applicable

    hi amitchandak ,

     

    Actually, I want a date filter in the dashboard wherein users can select any 2 days, by which they can compare costs on the selected two days.

    • v-chenwuz-msft's avatar
      v-chenwuz-msft
      Community Support

      Hi Anonymous ,

       

      Create a new table for user to select the previous date via PreviousDate = VALUES('Table'[date])

       

      Then use this measure to get the values of previous date.

      PreviousCost = CALCULATE(SUM('Table'[Cost]),'Table'[date]=SELECTEDVALUE(PreviousDate[date]))
       
      Reault:

      Pbix in the end you can refer.

      Best Regards

      Community Support Team _ chenwu zhu

       

      If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        v-chenwuz-msft , how can I only show the last 3 months dates in the date filter?