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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
thisguy
Advocate I
Advocate I

Calculated Column from another column - change all but the latest date.

i have three columns - status, user and month.   the status is the same for every month for each user but it is only correct for the last month, all earlier entries should be "Active".

 

I had a solution in power query using a function that works on my home latest release power BI version, howerver my work power BI desktop is an older version due to IT policy and i get a function error.   

 

is there a way in DAX to produce the column i need?

 

how it is:

StatusUserMonth
CompleteUser11/01/2021
CompleteUser11/02/2021
CompleteUser11/03/2021
WithdrawnUser21/01/2021
WithdrawnUser21/02/2021
WithdrawnUser21/03/2021
ActiveUser31/01/2021
ActiveUser31/02/2021
ActiveUser31/03/2021

 

how it should be:

StatusUserMonth
Activeuser11/01/2021
ActiveUser11/02/2021
Completeuser11/03/2021
ActiveUser21/01/2021
ActiveUser21/02/2021
WithdrawnUser21/03/2021
ActiveUser31/01/2021
ActiveUser31/02/2021
ActiveUser31/03/2021
1 ACCEPTED SOLUTION

@thisguy ,

You can try this measure:

Measure = 
VAR currentUser = MAX ( T[User] )
VAR latestDate = MAXX ( FILTER ( ALL ( T ), T[User] = currentUser ), T[Month] )
VAR latestStatus =
    CALCULATE (
        MAX ( T[Status] ),
        T[User] = currentUser,
        T[Month] = latestDate
    )
RETURN
    IF ( MAX ( T[Month] ) = latestDate, latestStatus, "Active" )

ERD_0-1626241569154.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

8 REPLIES 8
SanketBhagwat
Solution Sage
Solution Sage

Can you please share the sample data file?

The data you provided seems to be incomplete as User2 has different status for same day.

 

Regards,

Sanket Bhagwat

appoligies - i have changed the data in the post.  should have been 3 users. 

ERD
Super User
Super User

@thisguy ,

you have 2 different values for the last month for User 2..

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

i've updated the post - it hsould have been 3 users. 

@thisguy ,

You can try this measure:

Measure = 
VAR currentUser = MAX ( T[User] )
VAR latestDate = MAXX ( FILTER ( ALL ( T ), T[User] = currentUser ), T[Month] )
VAR latestStatus =
    CALCULATE (
        MAX ( T[Status] ),
        T[User] = currentUser,
        T[Month] = latestDate
    )
RETURN
    IF ( MAX ( T[Month] ) = latestDate, latestStatus, "Active" )

ERD_0-1626241569154.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Hi ERD,  thanks for the reply - i'm not sure if i am doing something wrong but when i'm doing it i get "Active" for all results

thisguy_0-1626391307967.png

 

  

@thisguy , the code is for the measure, your image shows a calculated column. You need a calculated column ? If so, here the code:

New status = 
VAR currentUser = T[User]
VAR latestDate = 
    MAXX ( FILTER ( ALL ( T[User], T[Month] ), T[User] = currentUser ), T[Month] )
VAR latestStatus =
    CALCULATE (
        MAX ( T[Status] ),
        T[User] = currentUser,
        T[Month] = latestDate
    )
RETURN 
    IF ( T[Month] = latestDate, latestStatus, "Active" )

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

ERD thankyou for this - i was also able to get the first response to work once i corrected my mistake so i'll accept that as the solution as it answers the original question.   

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors