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
xl0911
Helper III
Helper III

Show last 6 end of month

Hello,

 

I want to show last 6 end of month in a visual.

 

I have this DAX measure (base on this website: https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/)

 

--
--  This calculation item works together with the Previous Date table to show
--  6 months back from the currently selected date in the Date table.
--
'Previous Period'[Previous Period]."Previous 6 Months" =
 
VAR NumOfMonths = -6
VAR ReferenceDate = MAX ( 'Date'[Date] )
VAR PreviousDates =
    DATESINPERIOD (
        'Previous Date'[Date],
        ReferenceDate,
        NumOfMonths,
        MONTH
    )
VAR Result =
    CALCULATE (
        SUM(MyField),
        REMOVEFILTERS ( 'Date' ),
        KEEPFILTERS ( PreviousDates ),
        USERELATIONSHIP ( 'Previous Date'[Date], 'Date'[Date] )
    )
RETURN Result

 

In my model it works fine but I need to SUM only the last day in every month.

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @xl0911 ,

Please update the formula of the measure ['Previous Period'[Previous Period]."Previous 6 Months"] as below and check if it can return the correct result...

'Previous Period'[Previous Period]."Previous 6 Months" =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR Result =
    CALCULATE (
        SUM ( [MyField] ),
        REMOVEFILTERS ( 'Date' ),
        FILTER (
            'Previous Date',
            'Previous Date'[Date]
                IN {
                    EOMONTH ( ReferenceDate, -1 ),
                    EOMONTH ( ReferenceDate, -2 ),
                    EOMONTH ( ReferenceDate, -3 ),
                    EOMONTH ( ReferenceDate, -4 ),
                    EOMONTH ( ReferenceDate, -5 ),
                    EOMONTH ( ReferenceDate, -6 )
                }
        ),
        USERELATIONSHIP ( 'Previous Date'[Date], 'Date'[Date] )
    )
RETURN
    Result

 

If the above one can't help you get the expected result, could you please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And 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

2 REPLIES 2
sevenhills
Super User
Super User

Try this if @v-yiruan-msft reply is not working for you.

 

 

'Previous Period'[Previous Period]."Previous 6 Months" =
VAR ReferenceDate = MAX ( 'Date'[Date] )
VAR PreviousDates =
    FILTER (
            'Previous Date',
            'Previous Date'[Date]
                IN {
                    EOMONTH ( ReferenceDate, 0 ),
                    EOMONTH ( ReferenceDate, -1 ),
                    EOMONTH ( ReferenceDate, -2 ),
                    EOMONTH ( ReferenceDate, -3 ),
                    EOMONTH ( ReferenceDate, -4 ),
                    EOMONTH ( ReferenceDate, -5 )
                }
        )
VAR Result =
    CALCULATE (
        SUM(MyField),
        REMOVEFILTERS ( 'Date' ),
        KEEPFILTERS ( PreviousDates ),
        USERELATIONSHIP ( 'Previous Date'[Date], 'Date'[Date] )
    )
RETURN Result

 

Optional: I will say keep both in case you need as below:

sevenhills_0-1675358378619.png

sevenhills_1-1675358396888.png

 

 

 

 

 

v-yiruan-msft
Community Support
Community Support

Hi @xl0911 ,

Please update the formula of the measure ['Previous Period'[Previous Period]."Previous 6 Months"] as below and check if it can return the correct result...

'Previous Period'[Previous Period]."Previous 6 Months" =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR Result =
    CALCULATE (
        SUM ( [MyField] ),
        REMOVEFILTERS ( 'Date' ),
        FILTER (
            'Previous Date',
            'Previous Date'[Date]
                IN {
                    EOMONTH ( ReferenceDate, -1 ),
                    EOMONTH ( ReferenceDate, -2 ),
                    EOMONTH ( ReferenceDate, -3 ),
                    EOMONTH ( ReferenceDate, -4 ),
                    EOMONTH ( ReferenceDate, -5 ),
                    EOMONTH ( ReferenceDate, -6 )
                }
        ),
        USERELATIONSHIP ( 'Previous Date'[Date], 'Date'[Date] )
    )
RETURN
    Result

 

If the above one can't help you get the expected result, could you please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And 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.

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.