Forum Discussion

EmilyM2019's avatar
EmilyM2019
Helper II
6 years ago
Solved

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,

  • Add a column

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

3 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    Add a column

    ColumnAdded = SWITCH(TableX[Customer],  "A", TableX[Working days count], 
                                            "B", TableX[Calendar days count],
                                          0)
  • Jimmy801's avatar
    Jimmy801
    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