Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Differences between last 5 months

Hi all,

 

Im currently looking to calculate the total cases difference between this month towards last 5 months. Just wondering how can I achieve that. 

Here's a screenshot of how my data is looking right now:

shawn0702_0-1665116434954.png

Regards,

Shawn

1 ACCEPTED SOLUTION

Hi @Theriaux ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:

 

Difference = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR _enddate =
    EOMONTH ( EDATE ( _seldate, -1 ), 0 )
VAR _startdate =
    EDATE ( _enddate, -5 ) + 1
VAR _pre5years =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] >= _startdate
                && 'Table'[Date] <= _enddate
        ),
        [Total cases]
    )
RETURN
    IF ( ISBLANK ( _pre5years ), BLANK (), [Total cases] - _pre5years )

 

yingyinr_0-1665392259000.png

 

You can refer the following links to get the values for last N months:

Display Last N months data in Power BI

Display Last N Months & Selected Month using Single Date Dimension in Power BI

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@Anonymous , do you need MOM ?

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Anonymous
Not applicable

Hey @amitchandak , unfortunately, what I am looking for is this month compared to last 5 months (total cases for last 5 months).

Hi @Theriaux ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:

 

Difference = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR _enddate =
    EOMONTH ( EDATE ( _seldate, -1 ), 0 )
VAR _startdate =
    EDATE ( _enddate, -5 ) + 1
VAR _pre5years =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] >= _startdate
                && 'Table'[Date] <= _enddate
        ),
        [Total cases]
    )
RETURN
    IF ( ISBLANK ( _pre5years ), BLANK (), [Total cases] - _pre5years )

 

yingyinr_0-1665392259000.png

 

You can refer the following links to get the values for last N months:

Display Last N months data in Power BI

Display Last N Months & Selected Month using Single Date Dimension in Power BI

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Also @v-yiruan-msft , just one small question again if you don't mind. If I would like to calculate the difference between lets say September and April (not the difference between September and the total number of cases from April to August, just september and april itself). How can I achieve that?

 

Regards,

Shawn

Hi @Anonymous ,

I updated my sample pbix file(see the attachment), please check if that is what you want... You can create a measure as below to get the difference with the current month value and the value for 5 months ago:

Difference2 = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR _enddate =
    EOMONTH ( EDATE ( _seldate, -1 ), 0 )
VAR _pre5month =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] >= EDATE ( _enddate, -5 ) +1
                && 'Table'[Date] <= EDATE ( _enddate, -4 ) 
        ),
        [Total cases]
    )
RETURN  IF ( ISBLANK ( _pre5month ), BLANK (), [Total cases] - _pre5month )

yingyinr_0-1665450195899.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hey @v-yiruan-msft , 

thanks for your help. That is what I am looking for.

 

Cheers,

Shawn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.