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


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.