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
Shorey
Regular Visitor

Filter within a calculate field across 2 different Dimensions

Hi (first time poster but have used a lot of solutions provided within the pages)

 

I have a fact table that i need it identify a MoM (Month On Month) change by a certain measure.  Which i can do however i now need to do it on a subset of the fact table.  Only the records that have had a claim (for example the table has 10,000 records of which only 2,000 have a claim).  I need to isolate the calculation to just these records.  For all the measures so far this has been achieved with the filter function.  However I now need to Filter on Date and a text field.  (hope that all makes sense). 

 

The code that i am trying to use (i think is correct as far as the syntax goes) is:

claimMoM = Var cLMeasy = Calculate( Key_measures[%Easy], all(Dim_datet),Dim_Datet[Month Rank], Dim_ClaimStatus[ClaimSts] in {"Fault","Non-Fault"}
= min('DIM_DateT'[Month Rank])-1)
Return if( cLMeasy = 0, Blank(), Key_measures[%Easy] - cLMeasy)
So this will only do the %Easy measure for only those records that have a Fault or Non-Fault record.  In theory this should work BUT.  I get an error telling me:
 
"MdxScript(Model) (187, 117) Calculation error in measure 'Key_measures'[ClaimMoM]; DAX comparison operations do not support comparing values of type True/False with values of type Integer"
 
I think this means having a date filter and an integer filter cannot be in the same calculation.
 
Does anyone know how i can overcome this issue.
Thanks in Advance!
4 REPLIES 4
johnt75
Super User
Super User

I think you've put the claim status check in the wrong place, in the middle of the check for month rank. Try

claimMoM =
VAR cLMeasy =
    CALCULATE (
        Key_measures[%Easy],
        ALL ( Dim_datet ),
        Dim_Datet[Month Rank]
            = MIN ( 'DIM_DateT'[Month Rank] ) - 1,
        Dim_ClaimStatus[ClaimSts] IN { "Fault", "Non-Fault" }
    )
RETURN
    IF ( cLMeasy = 0, BLANK (), Key_measures[%Easy] - cLMeasy )

Thanks, @johnt75 as I mentioned below to @SpartaBI (you both gave the same reply) the filter needs to be taking in to consideration when creating the previous month's results and comparing it to this month with the same filters.

SpartaBI
Community Champion
Community Champion

@Shorey not sure but I copied the code you sent and seems there was a mix in the lines. I just replaced the lines, try this and tell me if you get the error:
claimMoM = 
VAR cLMeasy =
    CALCULATE (
        Key_measures[%Easy],
        ALL ( Dim_datet ),
        Dim_Datet[Month Rank]
            = MIN ( 'DIM_DateT'[Month Rank] ) - 1,
        Dim_ClaimStatus[ClaimSts] IN { "Fault", "Non-Fault" }
    )
RETURN
    IF ( cLMeasy = 0, BLANK (), Key_measures[%Easy] - cLMeasy )

Thanks for your reply @SpartaBI that is much easier to read (i must get in the habit of laying the code like that).  However I no longer get the error but it is returning the same result i had before i tried to put the fault non-fault filter in - which suggests it isn't filtering on this factor.  I think it needs to be within the one calculation for the min statement.  I moved it up to after the key_measure, but that didn't work either. (no error message just not the correct result).

Thanks for trying though.

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.

Top Solution Authors