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

How can I calculate measures for unpivoted data in power BI?

I have the following unpivoted data in Power BI that I wish to get the number of working days between each process step, and then find the average working days for each account code

 

Since the data repeats, what is the best method of tackling this data problem? DAX gives errors for measure saying it cannot determine a single value

 

 

 

jsauerla_1-1616762449681.png

 

Do I simply need to pivot it, like below, or is this data just not workable?

 

jsauerla_2-1616762539011.png

 

 

 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to my understanding, you want to calculate the diff days between two steps of each accound code, right?

Please follow these steps:

 

1. Add a flag column

Flag = SWITCH([Process Step],"Upload",1,"Move",2,"Submit",3,"Review",4,"Approve",5) 

2. Add a Rank column

Rank = 
VAR a = [Account Code]
var b=[Process Change Date]

VAR t1 =
    FILTER ( ALL ( 'Table' ), 'Table'[Account Code] = a )
var t2=
    FILTER ( ALL ( 'Table' ), 'Table'[Account Code] = a && 'Table'[Process Change Date]=b )
RETURN
    RANKX (
        t1,
        RANKX ( t1, [Process Change Date],, ASC, SKIP ) * 100
            + RANKX ( t2, [Flag],, ASC, SKIP ) * 10,
        ,
        ASC,
        SKIP
    )

Then calculate the diff and average(measure):

Datediff =
VAR pre =
    CALCULATE (
        MAX ( 'Table'[Process Change Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account Code] = MAX ( 'Table'[Account Code] )
                && 'Table'[Rank]
                    = MAX ( 'Table'[Rank] ) - 1
        )
    )
RETURN
    DATEDIFF ( pre, MAX ( 'Table'[Process Change Date] ), DAY )
average working days =
AVERAGEX (
    FILTER ( 'Table', 'Table'[Account Code] = MAX ( 'Table'[Account Code] ) ),
    [Datediff]
)

The final output is shown below:

3.29.5.diff.PNG

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to my understanding, you want to calculate the diff days between two steps of each accound code, right?

Please follow these steps:

 

1. Add a flag column

Flag = SWITCH([Process Step],"Upload",1,"Move",2,"Submit",3,"Review",4,"Approve",5) 

2. Add a Rank column

Rank = 
VAR a = [Account Code]
var b=[Process Change Date]

VAR t1 =
    FILTER ( ALL ( 'Table' ), 'Table'[Account Code] = a )
var t2=
    FILTER ( ALL ( 'Table' ), 'Table'[Account Code] = a && 'Table'[Process Change Date]=b )
RETURN
    RANKX (
        t1,
        RANKX ( t1, [Process Change Date],, ASC, SKIP ) * 100
            + RANKX ( t2, [Flag],, ASC, SKIP ) * 10,
        ,
        ASC,
        SKIP
    )

Then calculate the diff and average(measure):

Datediff =
VAR pre =
    CALCULATE (
        MAX ( 'Table'[Process Change Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account Code] = MAX ( 'Table'[Account Code] )
                && 'Table'[Rank]
                    = MAX ( 'Table'[Rank] ) - 1
        )
    )
RETURN
    DATEDIFF ( pre, MAX ( 'Table'[Process Change Date] ), DAY )
average working days =
AVERAGEX (
    FILTER ( 'Table', 'Table'[Account Code] = MAX ( 'Table'[Account Code] ) ),
    [Datediff]
)

The final output is shown below:

3.29.5.diff.PNG

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Add an index column and then try to pivot and check.

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

Anonymous
Not applicable

@amitchandak Do I add the index column before the pivot or after? 

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.