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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

SUM different columns based on selected value(s)

Hi,

I have a Date table like this

DateYear-MonthSwedenDenmarkNorway
2020-01-012020-01010
2020-01-022020-01010
2020-01-032020-01110
2020-01-042020-01111
2020-01-052020-01001
2020-01-062020-01001
2020-01-072020-01111
2020-01-082020-01110
2020-01-092020-01111
2020-01-102020-01110

 

Then I have the Company table like this

 

CompanyCountry
Swedish CompanySweden
Danish CompanyDenmark
Norwegian CompanyNorway

 

Would like to calculate Sales per working day for each company based on the total working day from the calendar. So I did the following measures:

 

Working day = SWITCH(TRUE(),
    SELECTEDVALUE(dimCompany[Country])="Sweden",SUM(dimDate[Sweden]),
    SELECTEDVALUE(dimCompany[Country])="Norway",SUM(dimDate[Norway]),
    SELECTEDVALUE(dimCompany[Country])="Denmark",SUM(dimDate[Denmark]),
    0)

Sales per working day = DIVIDE([Sales],[Working day],0)

 

 

It works well if I just choose one country... of course. So if I would like to choose more than one country, how should I write my DAX?

 

Example: If I pick Swedish and Danish Company, I want to see the result of: (SUM(dimDate[Sweden])+SUM(dimDate[Denmark]))/2

If I pick 3 companies, I want to see the result of (SUM(dimDate[Sweden])+SUM(dimDate[Denmark])+SUM(dimDate[Norway]))/3

 

Thank you very much.

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@Anonymous Well, you could use the IN operator like

 

"Sweden" IN DISTINCT('Company'[Country]) && "Norway" IN DISTINCT('Company'[Country])

 

That said, it would be far better to unpivot the country columns in your first table and create a relationship between your two tables and then there is zero need for fancy DAX.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.