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
Fxelixe
Frequent Visitor

IF statement not adding on Category Level

Hello,

 

So I got some issue on applying my measure on higher levelv of category.

Here's my data set:

Fxelixe_0-1671163602099.png

 

GroupIDXYZHave X Y Z
AA011000010000100001
AA021000010000100001
AA0301000000
AA0401000000
AA0501000000
AA061000010000100001
AA07100001000000
AA081000010000100001
BA0910000000
BA10100000100000
BA1100100000
BA1200100000
BA1300100000
BA14010000100000
BA15010000100000
BA161000010000100001
BA17100001000000
BA1810000000
CA1910000000
CA2010000000
CA2110000000
CA2210000000
CA2301000000
CA24010000100000
CA251000010000100001
CA261000010000100001
CA271000010000100001
CA281000010000100001

On Excel we can use if and countif statement to determine the have XYZ parameter

Desisred Output
A4
B1
C4


But on DAX, I Got 

Row LabelsSum of Have X Y Z
A1
B1
C1
Grand Total1


Here's my DAX Calculation

Have XYZ = 

Var __Unit = 'Value'[Sales]
 
Var Item1 =
CALCULATE(IF(isblank('Value'[Sales]),0,IF('Value'[Sales]>0,1,0)),filter('Time','Time'[Month] = "Nov"),filter('Product','Product'[Code] = "X"))

Var Item2 =
CALCULATE(IF(isblank('Value'[Sales]),0,IF('Value'[Sales]>0,1,0)),filter('Time','Time'[Month] = "Nov"),filter('Product','Product'[Code] = "Y"))

Var Item3 =
CALCULATE(IF(isblank('Value'[Sales]),0,IF('Value'[Sales]>0,1,0)),filter('Time','Time'[Month] = "Nov"),filter('Product','Product'[Code] = "Z"))

Return
IF((Item1+Item2+Item3)=3,1,0)


Thank you

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1671164966089.png

 

 

Jihwan_Kim_0-1671164942775.png

 

 

Desired outcome measure: =
SUMX (
    ADDCOLUMNS (
        DISTINCT ( 'Group'[ID] ),
        "@condition",
            IF (
                COUNTROWS (
                    CALCULATETABLE (
                        FILTER ( 'Value', 'Value'[Sales] <> 0 ),
                        'Time'[Month] = "Nov"
                    )
                ) = 3,
                1
            )
    ),
    [@condition]
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1671164966089.png

 

 

Jihwan_Kim_0-1671164942775.png

 

 

Desired outcome measure: =
SUMX (
    ADDCOLUMNS (
        DISTINCT ( 'Group'[ID] ),
        "@condition",
            IF (
                COUNTROWS (
                    CALCULATETABLE (
                        FILTER ( 'Value', 'Value'[Sales] <> 0 ),
                        'Time'[Month] = "Nov"
                    )
                ) = 3,
                1
            )
    ),
    [@condition]
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thank you for the inspiration. hope this also can help others.

tamerj1
Super User
Super User

Hi @Fxelixe 
[Group] and [ID] from which table(s)? [Sales] is a measure right?

the group itself is on seperate table, [Sales] is column. the DAX only for "Have XYZ" Calculation. after that I drag group to the row and the Have XYZ measure to the value section.

its challenging for me to create logic of ID that buy specific products (in this case X Y Z). and then applies it of group level because the IF statement on my measure also applied on region level (i expect only applied on id level and sum it on region level)

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