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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
ScottA
Frequent Visitor

Transform Row Value based on multiple other criteria

Hi All

 

I’ve got a data set that looks like the below. Example data, but I’ve tried to illustrate that one data set contains data for multiple employees against many different categories.

 

I’m specifically interested in the ‘Overnight’ Category at the moment.

 

Rows 1 and 3 of the data refer to employee 123 overnighting in Hamilton. They actually only stay in Hamilton on the night of the 22/05, but the logic is such that the overnight ‘starts’ on the 22/05 and ‘finishes’ on 23/05, hence the 2 rows of data.

 

The last 3 rows of the table illustrate a similar scenario, in that the employee stays in Queenstown on the night of the 1st and 2nd of June, and leaves Queenstown on the 3rd June.

 

I need to be able to transform the data such that if there are records for the same employee, of category ‘Overnight’, which fall on consecutive dates then it only counts the first instance. E.g. the Hamilton overnight counts as 1 and the Queenstown overnight counts as 2, versus the 2 and 3 respectively which come through in the original report. As in the table, it’s worth noting that data tends to be in date order based on all employees so its possible that the consecutive overnight dates are not necessarily in consecutive rows.

 

See ideal output column – doesn’t have to be a new column, just trying to illustrate the ideal result such that it can be used in graphs etc

 

The extent of my knowledge so far has been self taught through online resources such as this, so apologies if this is a stupid question. I'm using power BI desktop and the end result is to be used in a dashboard. So far I've managed to get by with creating new measures and columns using DAX to achieve what I need.

 

Thanks for your help!

Employee NumberResourceLocationRolePosition 1Position 2DateCategoryDetailValue Ideal output (overnight category only)
123Office WorkerAKLAccountsManager 22/05/2018OvernightHamilton1 1
205EngineerWLGTechnicianAssistant2IC22/05/2018Worked MinsWorked Mins360  
123Office WorkerAKLAccountsManager 23/05/2018OvernightHamilton1 0
205EngineerWLGTechnicianAssistant2IC23/05/2018Worked MinsWorked Mins600  
123Office WorkerAKLAccountsManager 24/05/2018LeaveSick1  
205EngineerWLGTechnicianAssistant2IC24/05/2018Worked MinsWorked Mins510  
123Office WorkerAKLAccountsManager 25/05/2018LeaveSick1  
205EngineerWLGTechnicianAssistant2IC25/05/2018Worked MinsWorked Mins500  
123Office WorkerAKLAccountsManager 1/06/2018OvernightQueenstown1 1
123Office WorkerAKLAccountsManager 2/06/2018OvernightQueenstown1 1
123Office WorkerAKLAccountsManager 3/06/2018OvernightQueenstown1 0

 

2 ACCEPTED SOLUTIONS
v-yuta-msft
Community Support
Community Support

Hi ScottA,

 

To achieve your requirement,  create a calculate column using DAX formula like this:

output =
CALCULATE (
    COUNT ( Table1[Value] ),
    FILTER (
        Table1,
        Table1[Date]
            = EARLIER ( Table1[Date] ) + 1
            && Table1[Employee Number] = EARLIER ( Table1[Employee Number] )
            && Table1[Category] = "Overnight"
    )
)

The result is as below and you can refer to PBIX here: https://www.dropbox.com/s/ecb7a6zdncdcxl4/Transform%20Row%20Value%20based%20on%20multiple%20other%20...

1.PNG 

 

Regards,

Jimmy Tao

View solution in original post

Hi Jimmy

 

Thank you very much, this formed 90% of the basis of my solution. 

 

For other's benefit, I had a couple of unexpected consequences when I used the suggested solution;

1) The calculate column produced 0's, 1's, and 2's - I only expected 0's and 1's

2) The calculate column produced non zero values against rows that were not the overnight category.

 

As far as I can tell both of these were generated by situations I hadn't considered when i posted the example data in original post;

1) Multiple night overnights could be in different cities. E.g. In the queenstown example above, if night 2 had been in Wanaka the data would be across 4 rows instead of 3 and it double counts the first day - see below.

 

Employee NumberResourceLocationRolePosition 1Position 2DateCategoryDetailValueIdeal output (overnight category only)output
123Office WorkerAKLAccountsManager 01/06OvernightQueenstown112
123Office WorkerAKLAccountsManager 02/06OvernightQueenstown101
123Office WorkerAKLAccountsManager 02/06OvernightWanaka111
123Office WorkerAKLAccountsManager 03/06OvernightWanaka10 

 

2) It was common (but not reflected in the example data) that an employee would have something else (e.g. Leave, or worked mins) the same day they started the overnight, so it would count 1 against the other category on this first day of the overnight.

 

I managed to rectify both by making a small adjustment to Jimmy's formula, as below.

CALCULATE(COUNT(Table1[Value]), FILTER(Table1, Table1[Date] = EARLIER(Table1[Date]) +1 && Table1[Employee Number] = EARLIER(Table1[Employee Number]) && EARLIER(Table1[Category]) = "Overnight"),FILTER(Table1,Table1[Detail]=EARLIER(Table1[Detail])))

 

Anyway good to go now, thanks again!

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi ScottA,

 

To achieve your requirement,  create a calculate column using DAX formula like this:

output =
CALCULATE (
    COUNT ( Table1[Value] ),
    FILTER (
        Table1,
        Table1[Date]
            = EARLIER ( Table1[Date] ) + 1
            && Table1[Employee Number] = EARLIER ( Table1[Employee Number] )
            && Table1[Category] = "Overnight"
    )
)

The result is as below and you can refer to PBIX here: https://www.dropbox.com/s/ecb7a6zdncdcxl4/Transform%20Row%20Value%20based%20on%20multiple%20other%20...

1.PNG 

 

Regards,

Jimmy Tao

Hi Jimmy

 

Thank you very much, this formed 90% of the basis of my solution. 

 

For other's benefit, I had a couple of unexpected consequences when I used the suggested solution;

1) The calculate column produced 0's, 1's, and 2's - I only expected 0's and 1's

2) The calculate column produced non zero values against rows that were not the overnight category.

 

As far as I can tell both of these were generated by situations I hadn't considered when i posted the example data in original post;

1) Multiple night overnights could be in different cities. E.g. In the queenstown example above, if night 2 had been in Wanaka the data would be across 4 rows instead of 3 and it double counts the first day - see below.

 

Employee NumberResourceLocationRolePosition 1Position 2DateCategoryDetailValueIdeal output (overnight category only)output
123Office WorkerAKLAccountsManager 01/06OvernightQueenstown112
123Office WorkerAKLAccountsManager 02/06OvernightQueenstown101
123Office WorkerAKLAccountsManager 02/06OvernightWanaka111
123Office WorkerAKLAccountsManager 03/06OvernightWanaka10 

 

2) It was common (but not reflected in the example data) that an employee would have something else (e.g. Leave, or worked mins) the same day they started the overnight, so it would count 1 against the other category on this first day of the overnight.

 

I managed to rectify both by making a small adjustment to Jimmy's formula, as below.

CALCULATE(COUNT(Table1[Value]), FILTER(Table1, Table1[Date] = EARLIER(Table1[Date]) +1 && Table1[Employee Number] = EARLIER(Table1[Employee Number]) && EARLIER(Table1[Category]) = "Overnight"),FILTER(Table1,Table1[Detail]=EARLIER(Table1[Detail])))

 

Anyway good to go now, thanks again!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.