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.
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.
Solved! Go to Solution.
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
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:
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
104 | |
95 | |
80 | |
67 | |
62 |
User | Count |
---|---|
147 | |
109 | |
107 | |
85 | |
63 |