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
mumair
Helper I
Helper I

How to filter a measure by all values

So currently I have DAX code as follows:

 

Measure = sumx(FILTER(Qty, Qty[ID #] = "53101"), [Sales])

 

This correctly sums up all the sales for a given ID. However, I want to do this for all sales across all IDs. How do I do this? Also, sales is a measure and not a column if that makes a difference.

12 REPLIES 12
ibarrau
Super User
Super User

Hi there. I'm sorry, but you should tell us more details about tables and the measure sales in order to help. If you just need sum a column of a table with and axis of another table, just relate them in Relationships View. Then you can add the columns in a single visualization set the numeric one to sum and you are ready to go.

 

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Let's say my table looks like this

 

ID # | Sales Amount

01 | 2

01 | 3

01 | 3

01 | 5

01 | 1

01 | 3

02 | 5

02 | 6

02 | 3

03 | 3

03 | 1

 

I want ONE DAX function that will sum up the sales amount per ID number. This data is hypothetical. My real dataset is much longer and has more columns, but for the time being, I am only concerned about these two particular columns. The sales amount is measure generated from another table.

Hi @mumair,

 

You can use max function to get current row content, then use it as the varibale to filter all table.

 

Below formula will summary amounts with has the same id:

Total= SUMX(FILTER(ALL(Table),[ID]=MAX(Table[ID])),[Sales Amount])

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Ok, that is not the table or an example of it because the measure is not from the table. Tell us the two tables involved, how are they related. Because at now, there is no problem. You can add the id and the measure to any visualization and it will work. Axis = not sumarize id and Value = Sales. You can make table, bar chart, etc.

 

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Alright, I have a time table and a quantity table. They are related by shipment number. One table has the shipments' quantities, and the other has the shipments' important times such as load and unload. I am interested in seeing the pump rate of different products on different ships. I calculated the pump rate for each shipment by dividing the metric tonnage of each shipment by the total loading time for each shipment. However, this is not the value I want as some shipments are on the same voyage and are the same product; thery are just for different customers and therefore registered as different shipments. What I want is the pump rate of all one type of cargo on the same ship, even if they go to different customers. Does this clarify things?

Yes, very much, now I get you need this measure to solve the issue. You need a way to SUM the sales of a DISTINCT table of IDs. I think this can help.

 

If Sales is already a SUM and the tables are related, then yo can do something like this:

= CALCULATE([Sales], SUMMARIZE(Table, Table[shipmentID])

or

= SUMX(DISTINCT(Table[ShipmentId]),[Sales])

 

Regards,

 

P/D I have never used the second way. I know the functions and in theory, they should work if the dependencies and sum are correct.


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Neither of these ways worked. They didn't change the original measure at all. I am a little confused at what you mean by "if Sales is already a SUM" though? Could it be a problem if it isn't?

Ok, let check this. What is sales? you mention it as a measure. Can you send the DAX formula of it? so we can check and construct the new measure with the columns involved in the calculation of sales.

 

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

I actually made up the sales and ID table for an illustration. One of my other posts details what I actually wanted.

 

Here's the DAX code for the measure:

 

Pump Rate =
(DIVIDE(SUM('Qty'[Vessel Measurement (MT)]), SUM('Time Log'[LoadTime]))) * 60

 

The vessel measurement is the amount of material on the ship for every shipment. The load time is the amount of time it took for the shipment to be loaded onto the vessel. The 60 is just to convert from minutes to hours.

Stachu
Community Champion
Community Champion

just to fully understand the data structure:

there are 2 tables:

Time Log

shipment nrLoadTime
152
220
352
456
512

and Qty

shipment nrVessel Measurement (MT)
110
220
330
440
550

which have join on 'shipment nr' - is it 1:1 or 1:many relationship?
is there a separate table with the unique 'shipment nr' that joins the two?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hi @Stachu,

 

Yes, if both two table contains the duplicate records, you should create a unique table to link them.(unique table one to many other tables)

Unique table sample:

Unique Table= DISTINCT(UNION(VALUES('Time Log'[shipment nr]),VALUES(Qty[shipment nr])))

 

>>which have join on 'shipment nr' - is it 1:1 or 1:many relationship?

Based on your sample data, I think it should be the one to one relationship on shipment nr column.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I'm not undestanding the idea of the measure or it's calculation. Do you know how acomplish the value manually or thinking of topic?

I can help you with functions, like saying you can sum all values ignoring filtering with all or allexcept function and distinct to separate the ids like the sales example. SUMX(ALL(DISTINCT([id example])), Qty[Vessel Measurement (MT)]) 

 

If you have the manual calculation, go step by step, first try to get the wish number of the first argument in the DIVIDE and then the second, once having both, create the final result.

 

regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

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.