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
newpbiuser01
Helper IV
Helper IV

Apply a Measure as a Filter to Another Measure

Hello,

 

I have a table that has spend for each month in the last three years. I am trying to create a visual to compare the year to date spend for each year. So as an example, for the latest year I have data for, I have spend data for January (Month = 1), the visual would show spend for Month 1 for all the previous years. 

 

My table is as follows:

YearMonthSpend

20221352
20222185
20223500
20224429
20225408
20226325
20227168
20228104
20229221
202210322
202211271
202212162
20231414
20232281
20233443
20234170
20235463
20236232
20237183
20238294
20239140
202310330
202311250
202312316
20241468

 

To get the latest month I have data for, I create the following measure: 

Last Month of Latest Year =
CALCULATE (MAX ( 'Table'[Month] ), FILTER ( 'Table', [Year] = MAX ( 'Table'[Year] ) ))

This measure gives me the following result: 

newpbiuser01_0-1705345436751.png

 

I then use this to calculate spend for all the years for this month: 

Spend for Latest Month =
CALCULATE (SUM ( 'Table'[Spend] ), FILTER ( 'Table', [Month] <= [Last Month of Latest Year] ))

 

 However, this gives me the following number which are clearly not filtering the previous years for just the latest month (1):

newpbiuser01_2-1705345516579.png

Now if I hardcode the number 1 in the Spend Measure, I get the right answer - which is the spend for the latest month of the latest year:

Spend for Latest Month_Month 1 = CALCULATE(SUM('Table'[Spend]), FILTER('Table',[Month] <= 1))
 
newpbiuser01_3-1705345591290.png

Why can I not use the Last Month of Latest Year measure to filter the data table? It should be passed as a number (1 in this case) to the Spend measure right? I'd appreciate any insights on what's going on here. 

1 ACCEPTED SOLUTION

Hi @newpbiuser01 ,

You can also try the next formula if you have the current month's data each time.

Measure = var _1month=MONTH(TODAY())
return
IF(MAX('Table'[Month])=_1month,MAX('Table'[Spend]),BLANK())

vrongtiepmsft_0-1705453550714.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

4 REPLIES 4
v-rongtiep-msft
Community Support
Community Support

Hi @newpbiuser01 ,

I have created a simple sample, please refer to it to see if it helps you.

Create measures.

Converts numeric columns to date columns for comparison.

date =DATE(MAX('Table'[Year]),MAX('Table'[Month]),1)

 Compare all dates to get the most recent date.

maxmonth = 
var _1= MAXX(ALL('Table'),[date])
return
IF([date]=_1,MAX('Table'[Month]),BLANK())

 Get the result.

result = var _1= MAXX(ALL('Table'),[maxmonth])
return
IF(MAX('Table'[Month])=_1,MAX('Table'[Spend]),BLANK())

vrongtiepmsft_0-1705367554004.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

 

Hi @v-rongtiep-msft ,

 

This works but only if I have a table or a bar chart where I have show each year.  I am trying to show the Year to Date difference Year over Year. 

 

How would I apply the year filter to say,

 

I added two measures in the pbix file you attached: 

1.  current year = CALCULATE([result], FILTER('Table', [Year] = MAX('Table'[Year])))

2. current year -1 = CALCULATE([result], FILTER('Table', [Year] = max('Table'[Year])-1))
3. Test = max('Table'[Year])-1
I used the Test measure to make sure I'm picking the right year (2023). The first measure works just fine, however the second one comes up blank: 
newpbiuser01_0-1705430985071.png (my apologies, I am unable to attach the pbix file)

How do I get the right answer in current year -1?

How can I get the spend to just the 1st month of year 2023 (the latest month I have 2024 data for)?



 

Hi @newpbiuser01 ,

You can also try the next formula if you have the current month's data each time.

Measure = var _1month=MONTH(TODAY())
return
IF(MAX('Table'[Month])=_1month,MAX('Table'[Spend]),BLANK())

vrongtiepmsft_0-1705453550714.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

 

Thank you 🙂

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.