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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
EmilyM2019
Helper II
Helper II

Dax help

Hello,

 

I need help with a simple calculation. In my data source I have 2 date count columns, one is working days and one is calendar days. 

 

I then have a field with a customer. I want a new column that looks at the customer column, and then based on the customer either returns the date count value of working days or calendar days.

 

So, if 'Customer' = "A"

return value of working days count

 

if 'Customer' = "B"

return value of calendar days count

 

Working days countCalendar days countCustomer
141196A
72101B
6794A
6184C
5475C
4968A

 

I just can't figure out how to do it.

 

Any help would be appreciated.

 

Regards,

1 ACCEPTED SOLUTION
HotChilli
Community Champion
Community Champion

Add a column

ColumnAdded = SWITCH(TableX[Customer],  "A", TableX[Working days count], 
                                        "B", TableX[Calendar days count],
                                      0)

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @EmilyM2019 

 

if you need a solution in Power Query, here is the solution

Create a new column and add this formula

if [Customer]="A" then [Working days count] else if [Customer]="B" then [Calendar days count] else "0"

here the complete solution

let
	Source = #table
	(
		{"Working days count","Calendar days count","Customer"},
		{
			{"141","196","A"},	{"72","101","B"},	{"67","94","A"},	{"61","84","C"},	{"54","75","C"},	{"49","68","A"}
		}
	),
    AddCustom = Table.AddColumn
	(
		Source, 
		"Custom", 
		each if [Customer]="A" then [Working days count] else if [Customer]="B" then [Calendar days count] else "0"
	)
in
	AddCustom

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

HotChilli
Community Champion
Community Champion

Add a column

ColumnAdded = SWITCH(TableX[Customer],  "A", TableX[Working days count], 
                                        "B", TableX[Calendar days count],
                                      0)

Thanks for the help. This worked perfectly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.