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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
okusai3000
Helper IV
Helper IV

Wrong Subtotals Matrix

Hello everyone,

 

First of all, I promise you that I've been using the searchbar but I couldn't find a proper answer.

 

I have the following graph, and I simply cannot get a proper subtotal. For instance, check out "AIROX". It says 82, but clearly is not the right sum.

Captura de pantalla 2020-09-21 a las 12.14.29.png

 

The measure is the following one:

Cant Equipos Antiguos = CALCULATE([*Cant Equipos];filter(values('Dim Descripcion Equipos y Fungibles'[Marca]);[*Antiguedad]<-180))
 
And I tried things as *Fixed Measure= if(HASONEVALUE('Fact Equipos'[Article_ID]..., but it doesn't work.
 
Any idea?
 
thanks!!
1 ACCEPTED SOLUTION

@AllisonKennedy ,

 

Finally with our consultant we arrived to the solution: We had to disable the relationship bewtween the calendar table (Dim Date) and the Fact Table (Fact Stock Equipos). This allowed us to have a proper subtotal, and in order to keep things ok with the original measures, I just add USERELATIONSHIP on them.

 

Anyway, thanks a lot for your kindness and help, 

View solution in original post

23 REPLIES 23
AllisonKennedy
Super User
Super User

Can you please share your model view? Looks like you're using two tables in this matrix - Fact Equipos and Dim Descripcion Equipos y Fungibles. Which table is Cant Equipos doing a count from?

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy There you go!

 

Captura de pantalla 2020-09-23 a las 9.12.23.png

 

Thanks!

Anyone ? 😞

@okusai3000 thanks for the data model - that's helpful.

Can you also please share the DAX for [cant equipos]? Since it is a measure, it can be doing anything - it doesn't actually matter which table it sits in within the data model, but does matter what the DAX looks like.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy , actually here's the PBIX https://we.tl/t-D9gxf5wV8a

 

thanks!

Here goes another up!

@okusai3000 I have been working on this a bit, but you have a very complex web of measures referencing measures, which makes it tricky to troubleshoot. Can you try using words to explain the purpose of your key measures - Cant Equipos, Antiguedad, Cant Equipos Antiguedad.

Please explain with specific reference to context, so what should be happening at the Brand and Sap code levels. I think a simplification of some of your other measures that are 'working' at the moment might help make this problem easier.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy ,

 

The only relevant measures are

*Cant Equipos; ---> Counts the last movement of each ID (esap_cod). 

*Antiguedad; --> Checks how much time has passed since the last movement of each ID

*Cant Equipos Antiguos -->Tries to check how many units are older than 180 days.

 

The issue is with *Cant Equipos Antiguos, where the subtotals doesn't seem to work properly....

 

Is that more clear?

 

thank you!

 

 

Thanks @okusai3000
Not really much more clear though, as in your pbix the Cant Equipos refers to another date measure, so what do you mean by 'last movement'? You're doing some complex calculations based on date filters.

Also, the Cant Equipos is doing a Distinct count, which has a big impact on subtotals, so need to consider context and how to count a esap_cod if it falls into two Marcas, though that will primarily impact your grand totals I think in this case rather than subtotals.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy ,

 

*Cant Equipos = calculate(distinctCOUNT('Fact Stock Equipos'[esap_cod]);
filter(all('Dim Date');
('Dim Date'[Date] <= max('Dim Date'[Date] ))))
 
Let me explain it. The DB shows the stock of some articles. We have a row per single article (esap_code) movement, and the "kind" of article is called "mmap_id". Everytime that one of them "moves", I mean, if is in stock, or is being used, it will be reflected on the DB, showing the date(fecha) and the new state (aprt_estado)
 
This is the table:
Fecha --  nmap_id -- esap_cod  -- aprt_estado
 
 
Thus, if I want to see the stock of the esap_cod category "Spoons", I need to COUNT all the LAST movement of each esap_code (every single Spoon )until a certain date.
 
Is maybe more clear?
 
Thanks!!
 
 

That kind of makes sense, but then why are we counting esap_cod and not counting nmap_id?

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy , Indeed, while I was writing you the post, that caught my attention. I have just tried with the nmap_id, and this makes problems with the subtotals of the kind of article (esap_cod). 

 

Captura de pantalla 2020-09-29 a las 12.05.31.png

 

 

 

EDIT: @AllisonKennedy , So sorry, but the mmap_id, actually... is the kind of article!, and esap_Cod EACH article.... that's why the measure was done in that way....

From my tests with your sample file, those are the correct subtotals for the Marca - you only have 3 distinct values for nmap within Airox: E18, E63, E65.

Maybe you need to combine esap and nmap to count distinct values for those? Something like using this: sumx(VALUES('Fact Stock Equipos'[esap_cod]), distinctCOUNT('Fact Stock Equipos'[mmap_id]))

for your cant equipos?

That doesn't fully solve your problem, but I think we're getting closer.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy , did you reach to read my last message? I was saying that at the end, the original formula was all right. I mean, the reason why I'm using DISTINCTCOUNT with esap_cod is because, esap_cod is the article itself (the unit), and nmap_id the category.

 

Any extra advice? 😕

 

thanks!

 

 

@AllisonKennedy ,

 

Finally with our consultant we arrived to the solution: We had to disable the relationship bewtween the calendar table (Dim Date) and the Fact Table (Fact Stock Equipos). This allowed us to have a proper subtotal, and in order to keep things ok with the original measures, I just add USERELATIONSHIP on them.

 

Anyway, thanks a lot for your kindness and help, 

Yay! Glad it's working now and thanks for the update - sorry it has been a busy week. Please mark your own reply as a solution so people with a similar problem can benefit from it. 🙂

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Greg_Deckler
Super User
Super User

@okusai3000 Have you read through this? This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

You would need to SUMMARIZE or GROUPBY on both of the columns in your rows hiearchy of your matrix.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@okusai3000 , Try like

CALCULATE(Sumx(filter(values('Dim Descripcion Equipos y Fungibles'[Marca]);[*Antiguedad]<-180);[*Cant Equipos]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak , Didn't work. I mean, is still showing the same.

 

@Ronald123 , I already followed her video and she talks about the use of HASONEVALUE. If I use that, it also doesn't work.

@okusai3000 ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.