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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
aisberg
Frequent Visitor

DAX equivalent to PRODUCT() on a Measure in a variable context?

I need to calculate in a flexible context per day:

 

A_prod(day 1) = A(day 1)
A_prod(day 2) = A(day 1) * A(day 2)
A_prod(day 3) = A(day 1) * A(day 2) * A(day 3)

 

and so on.

If [A] would be a column, I could use PRODUCT(), for example this:

Measure A_prod := 
CALCULATE(
PRODUCT('table'[A]);
FILTER(
ALLSELECTED( 'table');
'table'[date] <= MAX('table'[date])
)
)

Calculating this for each date I would be near to my target. But this will work only on a colum 'table'[A] with fixed data. And my [A] is not a columns but a measure and it's value depends on the context.

To be less abstract:
[A] := SUM([B] * [C]) / SUM ([C])
but the elements to be included into the SUM depend on the content.

I tried to use ADDCOLUMNS on a SUMMARIZE table, but the context is not used in the calculations, SUMMARIZE table seams to be the same in any context.

ProdX 3 := 
CALCULATE(
PRODUCTX (
ADDCOLUMNS ( SUMMARIZE ( 'MG_Datum_Mandant_Portfolio', 'MG_Datum_Mandant_Portfolio'[Datum] ), "TWR", [TWR_PF_BW_x_Vol_share_VT div Vol_share_VT] ),
[TWR]
);
FILTER(
ALLSELECTED( 'MG_Datum_Mandant_Portfolio');
'MG_Datum_Mandant_Portfolio'[Datum] <= MAX('MG_Datum_Mandant_Portfolio'[Datum])
)
)

--with ProdX 4 I get the same result as in ProdX 3

ProdX 4 :=
CALCULATE(
PRODUCTX (
ADDCOLUMNS ( SUMMARIZE ( ALLSELECTED('MG_Datum_Mandant_Portfolio'), 'MG_Datum_Mandant_Portfolio'[Datum] ), "TWR", [TWR_PF_BW_x_Vol_share_VT div Vol_share_VT] ),
[TWR]
);
FILTER(
ALLSELECTED( 'MG_Datum_Mandant_Portfolio');
'MG_Datum_Mandant_Portfolio'[Datum] <= MAX('MG_Datum_Mandant_Portfolio'[Datum])
)
)

 

 

4 REPLIES 4
aisberg
Frequent Visitor

y error was the wrong usage of ALLSELECTED

A good article is here: https://www.sqlbi.com/articles/the-definitive-guide-to-allselected/

I did a test with COUNT and I understand my error, need to filter ALLSELECTED only the date filter, but not the table wich context is required.

 

TWR_PF_BW Test01 =
CALCULATE(
COUNT('MG_Datum_Mandant_Portfolio_GroupBy'[TWR_PF_BW]);
FILTER(
ALLSELECTED( 'Datum');
'Datum'[Datum] <= MAX('Datum'[Datum])
)
)

Anonymous
Not applicable

 

// Try this. I wrote this blindly since I know nothing about
// what the model is and what you're really trying to achieve...
measure_ =
var __maxDate = max( 'MG_Datum_Mandant_Portfolio'[Datum] )
var __relevantDates =
	FILTER(
		ALLSELECTED ( 'MG_Datum_Mandant_Portfolio' ),
		'MG_Datum_Mandant_Portfolio'[Datum] <= __maxDate
	)
return
CALCULATE (
    PRODUCTX (
        ADDCOLUMNS (
            VALUES( 'MG_Datum_Mandant_Portfolio'[Datum] ),
            "TWR", [TWR_PF_BW_x_Vol_share_VT div Vol_share_VT]
        ),
        [TWR]
    ),
    __relevantDates
)

 

Anonymous
Not applicable

this worked for me, thanks! 😎

Greg_Deckler
Community Champion
Community Champion

Sample data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.