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
Anonymous
Not applicable

Changing Values Based on a Condition

Hi!

 

I'm having trouble with writing this DAX command. I'm trying to change a value based on the value in another column. For example, I attached an example power bi file and a picture of the chart.

 

For each transaction type, a number is assigned in a Status column, for Deaths,Dropped and Resignations its -1 and for Elected and Reinstated its 1.

I'm trying to have a total that includes everyone including the people who died (without counting the same person twice). I also have to show a breakdown of this number in a chart that is seperated by transaction. 

I was wondering if there was a way for me to have this count but if a person who was previously elected and is now dead, if there was a way for me to switch the value in the Status column for them being elected to -1 (instead of 1) and death to 1 (instead of -1)

2022-03-17 (1).png

 

https://drive.google.com/file/d/1eW3S5ZDKbShKp8wYvwYJZXUyo4oY91FM/view?usp=sharing 

 

Thank you for your help!!! Let me know if you have questions!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below measure.

 

new total: = 
VAR currenttransaction =
    MAX ( data[Transaction] )
VAR electedlist =
    SUMMARIZE (
        FILTER (
            SUMMARIZE ( ALL ( data ), data[name], data[date], data[Transaction] ),
            data[Transaction] = "Elected"
        ),
        data[name]
    )
VAR deathslist =
    SUMMARIZE (
        FILTER (
            SUMMARIZE ( ALL ( data ), data[name], data[date], data[Transaction] ),
            data[Transaction] = "Deaths"
        ),
        data[name]
    )
VAR bothlist =
    INTERSECT ( electedlist, deathslist )
VAR currentalltable =
    SUMMARIZE ( ALL ( data ), data[name], data[Transaction], data[Status] )
VAR exceptbothlistname =
    FILTER (
        SUMMARIZE ( ALL ( data ), data[name], data[Transaction], data[Status] ),
        NOT ( data[name] IN bothlist )
    )
RETURN
    SUMX (
        FILTER ( exceptbothlistname, data[Transaction] = currenttransaction ),
        data[Status]
    )
        + SUMX ( FILTER ( data, data[name] IN bothlist ), data[Status] * -1 )

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

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below measure.

 

new total: = 
VAR currenttransaction =
    MAX ( data[Transaction] )
VAR electedlist =
    SUMMARIZE (
        FILTER (
            SUMMARIZE ( ALL ( data ), data[name], data[date], data[Transaction] ),
            data[Transaction] = "Elected"
        ),
        data[name]
    )
VAR deathslist =
    SUMMARIZE (
        FILTER (
            SUMMARIZE ( ALL ( data ), data[name], data[date], data[Transaction] ),
            data[Transaction] = "Deaths"
        ),
        data[name]
    )
VAR bothlist =
    INTERSECT ( electedlist, deathslist )
VAR currentalltable =
    SUMMARIZE ( ALL ( data ), data[name], data[Transaction], data[Status] )
VAR exceptbothlistname =
    FILTER (
        SUMMARIZE ( ALL ( data ), data[name], data[Transaction], data[Status] ),
        NOT ( data[name] IN bothlist )
    )
RETURN
    SUMX (
        FILTER ( exceptbothlistname, data[Transaction] = currenttransaction ),
        data[Status]
    )
        + SUMX ( FILTER ( data, data[name] IN bothlist ), data[Status] * -1 )

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.

Anonymous
Not applicable

Thank you!! 

I was wondering how I would factor in the other transaction types like resignations and reinstatements. Also, I was wondering if there was a way for me to get the first transaction type of a person. Would I do Min(data[Transaction])?

Hi,

Thank you for your feedback.

I think you can use the similar way to identify the type.

And in a general situation, MIN function is used to get the first date of the transaction.

Thanks.

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! 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.