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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Get ALL sales per customer on product level - Hierarchy

Hey all,

 

I have a problem when trying to sum up the total customer sales on product level.

In this case, I would usually write a measure like:

 

SALES ALL =
CALCULATE(
[SALES],
ALL(PART_NO))

 

But, the issue is that this will return ALL parts under the customer, not only the part that the customer have bought.
So in the case where I have 10.000 different parts in table 'PARTS',
I would get ALL parts under the customer-product-matrix.

 

So I add to the measure (in bold) a filter that would exclude the parts where sales > 0:

 

SALES ALL =
CALCULATE(
[SALES],
FILTER(
'PARTS', [SALES] > 0),
ALL(PART_NO))

 

But that returns exactly the same as SALES does:

 

CUSTOMER | PART_NO | SALES | SALES ALL
ABC PART1 320e 320e
ABC PART2 220e 220e
ABC PART3 150e 150e
ABC PART4 120e 120e
CDE PART1 400e 400e
CDE PART2 300e 300e

 

When my desired result is:

 

CUSTOMER | PART_NO | SALES | SALES ALL
ABC PART1 320e 810e
ABC PART2 220e 810e
ABC PART3 150e 810e
ABC PART4 120e 810e
CDE PART1 400e 700e
CDE PART2 300e 700e

 

I tried the gurus: https://www.sqlbi.com/articles/clever-hierarchy-handling-in-dax/#

But they've a different method since it's the same table.

 

The tables are structured as following:

'CUSTOMERS' -->-- 'ORDERLINES' --<-- 'PARTS'

oscarrudnas_0-1602058993214.png

 

 

And it need to be a measure, since I have date filters on sales etc.

 

Any help from you guys?

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

SALES ALL = 
IF(
     isblank([Sales]),
       blank(),
     CALCULATE(
     [Sales],
     ALLNOBLANKROW(PBI_INVENTORY_PART[PART_NO])))
 
An if function seemed to do the work also. Thanks for the help!

View solution in original post

7 REPLIES 7
Fowmy
Super User
Super User

@Anonymous 

Try this way:

SALES ALL =
CALCULATE(
    [SALES],
    ALLSELECTED(PART_NO)
)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy 

This I have tried, and although it gives the correct values for the parts that has sales > 0, but it also includes all the 10.000 rows with no sales:

 

But that returns exactly the same as SALES does:

 

CUSTOMER | PART_NO | SALES | SALES ALL
ABC PART1 320e 810e
ABC PART2 220e 810e
ABC PART3 150e 810e
ABC PART4 120e 810e

ABC PART5 0e     810e

ABC PART6 0e     810e

ABC PART7 0e     810e

... 10 thousand rows until PART 10.000
CDE PART1 400e 700e
CDE PART2 300e 700e

 

So I don't see it as an acceptable solution. Of course it would be possible to make a visual level filter where sales > 0, but I find it not as safe, plus the measure takes a whole lot of processing power of going through 10k rows per each customer.

Anonymous
Not applicable

SALES ALL = 
IF(
     isblank([Sales]),
       blank(),
     CALCULATE(
     [Sales],
     ALLNOBLANKROW(PBI_INVENTORY_PART[PART_NO])))
 
An if function seemed to do the work also. Thanks for the help!

@Anonymous 

You may have enabled show Items with no data on the Customer and Part, try turning them off

 

Fowmy_0-1602060977698.png

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy 

The show items with no data was turned off,

but I didn't know it existed, so thanks for that.

 

Any comments regarding the IF-funtion solution? Would it be against the general rule of writing DAX (I guess)? 🙂

amitchandak
Super User
Super User

@Anonymous , I am not clear on the need of all(Part)

Try a measure like

sumx(filter(summarize(Table, Customer[customer], part[part], "_1", [sales]),[sales]>0),[_1])

Anonymous
Not applicable

@amitchandak Thanks, but this give the following:

It returns exactly the same as SALES does:

 

CUSTOMER | PART_NO | SALES | SALES ALL
ABC PART1 320e 320e
ABC PART2 220e 220e
ABC PART3 150e 150e
ABC PART4 120e 120e
CDE PART1 400e 400e
CDE PART2 300e 300e

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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