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
InsightSeeker
Helper III
Helper III

Need help with measure

Hello - I need to create a measure as

 

If trans_status is Sales return 1 and If trans_status is Refund return -1 else 0.

 

Table

trans_status
Sales
Sales
Sales
Refund
Sales
Refund
2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi, 

I assume the table contains more than one column, and I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1717920395865.png

 

 

expected result measure: = 
VAR _condition =
    HASONEVALUE ( 'Table'[trans_status] )
VAR _resultcondition =
    DIVIDE ( _condition, _condition )
RETURN
    _resultcondition
        * SWITCH ( SELECTEDVALUE ( 'Table'[trans_status] ), "Sales", 1, "Refund", -1, 0 )

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

@InsightSeeker 

 

Yes, there was an issue in Refund section, rather than " i typed ).

Fixed here:
WITHOUT Total:

Measure=
IF (
    HASONEVALUE ( 'Table'[trans_status] ),
    SWITCH ( MAX ( 'Table'[trans_status] ), "Sales", 1, "Refund", -1, 0 )
)

 

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

Appreciate your Kudos!! 

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

4 REPLIES 4
VahidDM
Super User
Super User

Hi @InsightSeeker 

 

Try this measure:
Measure = 
SWITCH (MAX( 'Table'[trans_status]),
"Sales",1,
"Refund",-1,
0
)

 

if you want to show nothing in total section if using this measure:

Measure = 

IF (
HASONEVALUE ( 'Table'[trans_status] ),
SWITCH (MAX( 'Table'[trans_status]),
"Sales",1,
"Refund",-1,
0
)
)

 

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

Appreciate your Kudos!! 

LinkedIn | Twitter | Blog | YouTube 

@VahidDM - These measure are not returning any result. Looking like something is missing.

@InsightSeeker 

 

Yes, there was an issue in Refund section, rather than " i typed ).

Fixed here:
WITHOUT Total:

Measure=
IF (
    HASONEVALUE ( 'Table'[trans_status] ),
    SWITCH ( MAX ( 'Table'[trans_status] ), "Sales", 1, "Refund", -1, 0 )
)

 

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

Appreciate your Kudos!! 

LinkedIn | Twitter | Blog | YouTube 

Jihwan_Kim
Super User
Super User

Hi, 

I assume the table contains more than one column, and I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1717920395865.png

 

 

expected result measure: = 
VAR _condition =
    HASONEVALUE ( 'Table'[trans_status] )
VAR _resultcondition =
    DIVIDE ( _condition, _condition )
RETURN
    _resultcondition
        * SWITCH ( SELECTEDVALUE ( 'Table'[trans_status] ), "Sales", 1, "Refund", -1, 0 )

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.