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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rp2022
Helper I
Helper I

Need help with a measure, tried but failed

Input: 

Category1Category2Count
A1100
A250
B1200
B2400
B3100
B4300
C1300
C2200
C3100

 

Expected Output:

Category1Category2CountSUM(Category2 =2)Comp
A110050High
A25050Equal
B1200400Low
B2400400Equal
B3100400Low
B4300400Low
C1300200High
C2200200Equal
C3100200Low

 

Tried: 

Var no =
            CALCULATE(
                SUM(Table[Count]),
                ALL(Table[Category1]),
                Table[Category2] = "2"
        )
But the results are wrong
1 ACCEPTED SOLUTION
Wilson_
Super User
Super User

Hello rp2022,

 

Try this for your Category 2 is 2 measure:

Category 2 is 2 Total = 
VAR Cat1 = SELECTEDVALUE ( 'Table'[Category1] )
VAR Filtered =
FILTER (
    ALL ( 'Table' ),
    'Table'[Category2] = 2 &&
    'Table'[Category1] = Cat1
)
VAR Result =
SUMX (
    Filtered,
    'Table'[Count]
)

RETURN Result

 

and try this for your Comp measure:

Comp = 
VAR SumCount = SUM ( 'Table'[Count] )
VAR CompValue = [Category 2 is 2 Total]
VAR CompVar = SumCount - CompValue
VAR Result =
SWITCH (
    TRUE(),
    CompVar > 0, "High",
    CompVar = 0, "Equal",
    CompVar <= 0, "Low"
)

RETURN IF ( ISINSCOPE ( 'Table'[Category1] ), Result )

 

This is what I get when I tested it with your sample data:

Wilson__0-1710201504804.png


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

lbendlin_0-1710202498356.png

Sum2 = CALCULATE(sum('Table'[Count]),'Table'[Category2]=2)
 
Comp =
var s = sum('Table'[Count])
return switch(TRUE(),
s>[Sum2],"High",
s=[Sum2],"Equal",
"Low")

 

Your Sum2 is what I tried first but for some reason, it didn't work for me. 😅 Your Comp measure is definitely more succinct though! 😄

 

Wilson__0-1710211072235.png

 

You also just have the one table of data right?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





You probably tried it as a measure.

Of course, they worked for me when they are both measures

Wilson_
Super User
Super User

Hello rp2022,

 

Try this for your Category 2 is 2 measure:

Category 2 is 2 Total = 
VAR Cat1 = SELECTEDVALUE ( 'Table'[Category1] )
VAR Filtered =
FILTER (
    ALL ( 'Table' ),
    'Table'[Category2] = 2 &&
    'Table'[Category1] = Cat1
)
VAR Result =
SUMX (
    Filtered,
    'Table'[Count]
)

RETURN Result

 

and try this for your Comp measure:

Comp = 
VAR SumCount = SUM ( 'Table'[Count] )
VAR CompValue = [Category 2 is 2 Total]
VAR CompVar = SumCount - CompValue
VAR Result =
SWITCH (
    TRUE(),
    CompVar > 0, "High",
    CompVar = 0, "Equal",
    CompVar <= 0, "Low"
)

RETURN IF ( ISINSCOPE ( 'Table'[Category1] ), Result )

 

This is what I get when I tested it with your sample data:

Wilson__0-1710201504804.png


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you so much, it worked like a charm

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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