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
jiji
Frequent Visitor

Return Unchanged status from latest week to prior weeks.

Hi guys, i have a table with 3 columns; Names, Status, date(8 weeks).
I want to return the names with unchanged status for the past weeks. Do you have any idea how to build it in dax? Really appreciate your help.

Data:

NAME          Week1       Week2      Week3       Week4        Week5        Week6
John             A                  B              C                C                C                  C
Ray               B                  B              B                 B                B                  B
Mary            A                  B               C                 D               E                  F

GOAL:
Name        STATUS       COUNT
John            C                 4
Ray              B                 6

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@jiji , First you have to unpivot the Week in power query

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

https://radacad.com/pivot-and-unpivot-with-power-bi

Duplicate column and split week out using

Split Column By Digit to Non Digit & Non Digit to Digit: https://youtu.be/tY4Yk1crS9s

 

In DAX Create Rank on week rank column you got now , Make sure you create a new week tbale and do week rank there . and join with you table 

Week Rank RANKX(all('Date'),'Date'[Week],,ASC,Dense)

 

 

This Week = CALCULATE(Max('Table'[Status]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(Table'[Status]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Sumx(Values(Table[name]) , calculate( If([This Week] = [Last Week], 1, blank()) ))

 

or

 

Sumx(Summarize(Table,Table[name], Date[Week]) , calculate( If([This Week] = [Last Week], 1, blank()) ))

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@jiji , First you have to unpivot the Week in power query

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

https://radacad.com/pivot-and-unpivot-with-power-bi

Duplicate column and split week out using

Split Column By Digit to Non Digit & Non Digit to Digit: https://youtu.be/tY4Yk1crS9s

 

In DAX Create Rank on week rank column you got now , Make sure you create a new week tbale and do week rank there . and join with you table 

Week Rank RANKX(all('Date'),'Date'[Week],,ASC,Dense)

 

 

This Week = CALCULATE(Max('Table'[Status]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(Table'[Status]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Sumx(Values(Table[name]) , calculate( If([This Week] = [Last Week], 1, blank()) ))

 

or

 

Sumx(Summarize(Table,Table[name], Date[Week]) , calculate( If([This Week] = [Last Week], 1, blank()) ))

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.

Top Solution Authors