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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
alsm
Helper III
Helper III

How does CALCULATE Filter when name in filter does not match any table column

Hello All,

I have a piece of DAX that works...I just do not get it why. Was I simply lucky or is this the way.

I have two related tables

Header Table
HeaderKeyDetailsKeyValidFromValidTo
H1D11Jan202231Dec2022
H2D215Feb202231Oct2022
H3D310Mar202215Sep2022
H4D47Feb202225Feb2022
H5D525Feb202214Apr2022
H6D612Jan202212Nov2022
H7D724Feb202224Feb2023
H8D816Mar202216Oct2022

 

Limit Table
HeaderKeyLimitVolumeValidFromValidTo
H15001Jan202215Feb2022
H145015Feb202231Mar2022
H14001Apr202231Dec2022
H270015Feb20221Mar2022
H25501Mar202231Oct2022
H325010Mar20221May2022
H32501May202215Sep2022
H47707Feb202225Feb2022
H580025Feb202214Apr2022
H645012Jan202231Mar2022
H63501Apr202212Nov2022
H760024Feb202224Feb2023
H832016Mar202216Oct2022

 

The volume limits corresponding to the Header keep on changing every month

e.g. in above table H1 volume limits was 500 from 1Jan to 15Feb and hen 450 from 15Feb to 31Mar and finally 400 from 1Apr to 31Dec

H15001Jan202215Feb2022
H145015Feb202231Mar2022
H14001Apr202231Dec2022

 

I want to show in a table only limits that changed in the selected month (i.e on 31Jan it should show 500, then 28Feb it should 450 but it should NOT show anything for 31Mar as limit did not change in month of March)

The DAX measure I wrote was

 

ChangedVolumeLimit = 
VAR VolLimFilter = FILTER(VolumeLimitTbl, VolumeLimitTbl[ValidFrom] > [PrevEoMFromSelect] && VolumeLimitTbl[ValidFrom] < [SelectEoM] && VolumeLimitTbl[ValidTo] > [SelectEoM])
VAR VolModifiedThisMonth = SELECTCOLUMNS(VolLimFilter, "hkey", [HeaderKey])

VAR NewHeaderFilter = FILTER(HeaderTbl, HeaderTbl[ValidFrom] > [PrevEoMFromSelect] && HeaderTbl[ValidFrom] > [SelectEoM] && HeaderTbl[ValidTo] > [SelectEoM])
VAR NewHeadersThisMonth = SELECTCOLUMNS(NewHeaderFilter, "newheaders", [HeaderKey])

VAR OnlyModifiedVolsNoNewHeaders = EXCEPT(VolModifiedThisMonth, NewHeadersThisMonth)

VAR NewVolLimit = CALCULATE(MAX(VolumeLimitTbl[LimitVolume]), OnlyModifiedVolsNoNewHeaders)

RETURN
    NewVolLimit

 

The measure works, the logic being filter all changes in volumes and then remove any new ones (as I want to show only changes in volume or brand new volumes)

alsm_1-1672085011745.pngalsm_2-1672085037001.pngalsm_3-1672085067601.png

 

My question is related to line 

 

VAR NewVolLimit = CALCULATE(MAX(VolumeLimitTbl[LimitVolume]), OnlyModifiedVolsNoNewHeaders)

 

How did this piece of code work? It should have been VolumeLimit[HeaderKey] in {list of valid keys}

 

Finally, is there a better way do it?

 

Thank you in advance for your help and guidance

1 REPLY 1
v-jialluo-msft
Community Support
Community Support

Hi  @alsm ,

 

If you just want to show the change in the selected month, you can try the following steps.

(1) Create a new measure

FLAG = 
VAR _MONTH = VALUES('CALENDAR'[Month])
VAR _FM = MONTH(MAX('Limit Table'[ValidFrom]))
RETURN IF(ISFILTERED('CALENDAR'[MONTH]),IF(_MONTH = _FM ,1,0),1)


(2)Apply filtering

vjialluomsft_0-1672130217970.png

 

(3)Final output

vjialluomsft_1-1672130247136.png

vjialluomsft_2-1672130268046.png

vjialluomsft_3-1672130289426.png

 

 

 

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

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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