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
Quiny_Harl
Resolver I
Resolver I

DAX that multiplies the total qty for all periods per individual price per item

Hi Folks,

 

I have the following data plotted in a matrix visual:

Quiny_Harl_2-1680263719605.png

- Date[Year Month] - dim table
- Product[Item] - dim table
- Qty =

CALCULATE(
          SUM(Fact_Table[QUANTITY_STD]),
          ALLSELECTED('Date')
        )

Qty should be the sum of Fact_Table[QUANTITY_STD] per Item regardless of time period, meaning for all displayed periods.

- Price - a measure that is calculated from the Fact Table. 
- Volume = Price * Qty
Now, if you look at the total Volume for 202303 it is not equal to 75,307.05 + 186,871.76 = 262,178.81.
I want the total for the month to be equal to (Item1 Qty x Price1) + (Item2 Qty x Price2)
where Qtys is the sum of Cost[QUANTITY_STD] for all periods for the respective item.
At the end, I will need to plot the Volume measure into a chart with dimension Year Month and the value for March 2023 should be 262,178.81 when Item 1 and Item 2 are selected from the Item slicer. 
How can I achieve this?

P. S. I have added a link with a file with sample data in the comment below. I think it will make it easier to understand the problem.

 

 

 

1 ACCEPTED SOLUTION
Quiny_Harl
Resolver I
Resolver I

Here is the DAX code that returns correct result:

Quiny_Harl_0-1680770850266.png

SUMX(
SUMMARIZE(
'FACT',
'Date'[Year Month],
'FACT'[FK_PRODUCT],
"price__", [Price_]
),
[price__] * CALCULATE(
[Qty],
REMOVEFILTERS('Date'[Year Month])
)
)

There are 2 things which are interesting for me and I cannot fully understand:
1. If you put ALLSELECTED in the CALCULATE statement, instead of REMOVEFILTERS, the result is wrong.
2. If you define Qty measure as a variable inside the measure, the result is wrong is well.



View solution in original post

3 REPLIES 3
Quiny_Harl
Resolver I
Resolver I

Here is the DAX code that returns correct result:

Quiny_Harl_0-1680770850266.png

SUMX(
SUMMARIZE(
'FACT',
'Date'[Year Month],
'FACT'[FK_PRODUCT],
"price__", [Price_]
),
[price__] * CALCULATE(
[Qty],
REMOVEFILTERS('Date'[Year Month])
)
)

There are 2 things which are interesting for me and I cannot fully understand:
1. If you put ALLSELECTED in the CALCULATE statement, instead of REMOVEFILTERS, the result is wrong.
2. If you define Qty measure as a variable inside the measure, the result is wrong is well.



amitchandak
Super User
Super User

@Quiny_Harl , Not very clear. But of the price is related item table on 1 side

 

you need a measure like

 

SUMX(Cost, cost[QUANTITY_STD]* related(item[price] ))

 

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

@amitchandak, thank you for your reply.
Here is a sample file: https://filetransfer.io/data-package/ZD3DY2wL#link

Quiny_Harl_0-1680632023939.png

If you look at the highlighted example.
(5696 x 7) + (1701 x 32) =
39,872 + 54,432 = 94,304 
However, instead of this total, we have 288,483 for Year Month 202211, which is wrong.
How can I make the total Volume equal to 94,304 and this value should be the same for all 3 visuals (meaning regardless if Item is used as a dimension or not)?

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.