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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
thod
Helper I
Helper I

Show last month of data on total

Hi,
I want my measure to show the latest month of data for current selection on the totals. If an attribute is blank in latest month for the current selection, it should not show anything in the total for the sepecific attribute. However, my current measure does not do what I want it to as it show data for nov in total for attribute A (see example).
So if the user selects months Oct, Nov, Dec, it should show data for each month however the totals should represent what is shown in Dec.
If the user selects months Oct, Nov, it should show data for each month however the totals should represent what is shown in Nov.
My measure looks like this:


VAR MaxDate =
MAX( 'FactTable'[DW_SK_Date] )
VAR Result =
CALCULATE(
SUM( 'FactTable'[Column1] ),
'DateTable'[DW_SK_Date] = MaxDate
)
RETURN
Result

 

Year2022Total
AttributeOctNovDecTotal
A24 44
B23444
C45666
Total812101010


The numbers in red symbolize it is wrong. It should be blank instead as Dec is blank for attribute A.

Hope it makes sense.

Br.,
Thomas

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@thod , With help date table create mtd measure use month and slicer from date table

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

 

Time Intelligence, Part of learning Power BI- https://youtu.be/cN8AO3_vmlY?t=27510
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

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

View solution in original post

4 REPLIES 4
thod
Helper I
Helper I

Thank you all. Seems like it works with the datesmtd and I might have been overcomplicated things.

Ashish_Mathur
Super User
Super User

Hi,

Try these measures

Total = SUM( 'FactTable'[Column1] )

Last date of last selected month = calculate(max('DateTable'[DW_SK_Date]),allselected('DateTable'[Month name]))

First date of last selected month = eomonth([Last date of last selected month],-1)+1

Total in last month = calculate([total],datesbetween('DateTable'[DW_SK_Date],[First date of last selected month],[Last date of last selected month]))

Measure=if(isinscope('DateTable'[Month name]),[Total],[Total in last month])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-jingzhang
Community Support
Community Support

Hi @thod 

 

Do you have "blank" data rows for attribute A with max date in December in the fact table? If so, your measure should work. If the max date for attribute A in the fact table is in November, that's why your measure doesn't work. 

 

Scenario One:

vjingzhang_0-1673924365835.png

Scenario Two:

vjingzhang_1-1673925620576.png

To get the expected result, you can use the following measure. I attached a pbix file at bottom which has both examples. 

New Measure = 
VAR MaxDate = MAX ( 'FactTable (2)'[Date] )
VAR MaxDate2 =
    IF (
        YEAR ( MaxDate ) = MAX ( 'DateTable'[Year] )
            && MONTH ( MaxDate ) = MAX ( 'DateTable'[Month] ),
        MaxDate,
        MAX ( 'DateTable'[Date] )
    )
VAR Result =
    CALCULATE ( SUM ( 'FactTable (2)'[Column1] ), 'DateTable'[Date] = MaxDate2 )
RETURN
    Result

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

amitchandak
Super User
Super User

@thod , With help date table create mtd measure use month and slicer from date table

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

 

Time Intelligence, Part of learning Power BI- https://youtu.be/cN8AO3_vmlY?t=27510
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

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.