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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Aedmunds
Frequent Visitor

Calculating the date of a day based on a week ending ... in Power BI Custom Column

I have a table with Resource, Week Ending (date), Mon, Tues, Weds, Thu, Fri, Sat and Sun - the user enters the number of days worked for each column (M-F,S,S)

 

I want to unpivot the data ... so I have 7 records for each row ... and show basically the days per day (where the day is an actual date.

 

Week Ending (Sunday) - 08-08-2021

 

I want to create the date for each row for each day 

 

Mon

Tue

Wed

Thu

Fri

Sat

 

Then my unpivoted data will essentially have the date and the hours worked

 

If I have tried a nested IF statement ... but not too strong with Code ... so its not looking good and can't work out why.

 

"IF( [DayOfWeek] = "Mon" then [Week Ending]-6, else [DayOfWeek]="Tue" then [Week Ending]-5, else [DayOfWeek]="Wed" then [Week Ending]-4,else [DayOfWeek]="Thu" then [Week Ending]-3, else [DayOfWeek]="Fri" then [Week Ending]-2, else [DayOfWeek]="Sat" then [Week Ending]-1, else [Week Ending])"

 

Cheers

Andre

1 ACCEPTED SOLUTION
Payeras_BI
Solution Sage
Solution Sage

Hi @Aedmunds ,

Payeras_BI_0-1628494817510.png

if [DayOfWeek] = "Mon" then Date.AddDays([Week Ending],-6) else if [DayOfWeek] = "Tue" then Date.AddDays([Week Ending],-5) else if [DayOfWeek] = "Wed" then Date.AddDays([Week Ending],-4) else if [DayOfWeek] = "Thu" then Date.AddDays([Week Ending],-3) else if [DayOfWeek] = "Fri" then Date.AddDays([Week Ending],-2) else if [DayOfWeek] = "Sat" then Date.AddDays([Week Ending],-1) else [Week Ending]
If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

2 REPLIES 2
Aedmunds
Frequent Visitor

Brilliant Mate!!!  😄 😄 😄

Payeras_BI
Solution Sage
Solution Sage

Hi @Aedmunds ,

Payeras_BI_0-1628494817510.png

if [DayOfWeek] = "Mon" then Date.AddDays([Week Ending],-6) else if [DayOfWeek] = "Tue" then Date.AddDays([Week Ending],-5) else if [DayOfWeek] = "Wed" then Date.AddDays([Week Ending],-4) else if [DayOfWeek] = "Thu" then Date.AddDays([Week Ending],-3) else if [DayOfWeek] = "Fri" then Date.AddDays([Week Ending],-2) else if [DayOfWeek] = "Sat" then Date.AddDays([Week Ending],-1) else [Week Ending]
If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors