Forum Discussion
Identify (filter) context of a table column to avoid unneeded calculations
Hi Ricardo77 ,
Believe this can be done in the following way.
- Create a disconnected table with the following code:
IDMOMENT = UNION(VALUES(FACTUAL[IDMOMENT]); {( "Delta")})
This create a table with all the IDMoments and an additional line with the value Delta
- Add the following measure:
SUMOFVALUES =
VAR MAXIMUM =
MAX ( FACTUAL[IDMOMENT] )
VAR minimum =
MIN ( FACTUAL[IDMOMENT] )
RETURN
SWITCH (
SELECTEDVALUE ( IDMOMENT[IDMOMENT] );
"Delta";
CALCULATE (
SUM ( FACTUAL[DW] );
FILTER ( FACTUAL; FACTUAL[IDMOMENT] = MAXIMUM )
)
- CALCULATE (
SUM ( FACTUAL[DW] );
FILTER ( FACTUAL; FACTUAL[IDMOMENT] = minimum )
);
CALCULATE (
SUM ( FACTUAL[DW] );
FILTER ( FACTUAL; FACTUAL[IDMOMENT] = MAX ( IDMOMENT[IDMOMENT] ) )
)
)
- Add a slicer with the column FACTUAL[IDMOMENT]
- Create your matrix with the following setup:
- Rows: Factual[dimension]
- Columns: IDMOMENT[IDMOMENT]
- Values: [SUMOFVALUES]
As you can see below the column Delta is on the end of the data and no need to hide it on the several other columns, be aware that this solution has two limitations:
- IDMOMENT needs to be in text (because of the delta)
- The calculation is only on MAX and MIN values selected so if you select more IDMOMENTS they will only consider max and minimum values and not the values in between.
If you want to overcome those measures needs to be changed a little bit.
Check PBIX file attach.
- Ricardo776 years ago
Helper II
hello MFelix , what a great piece of DAX code, Jesus 😂!
I'll try it out and tell something after.
Please allow me just a few comments & outburts ("desabafos", as we say in portuguese):
1- DAX is not easy, this doesn't help end users (namely business users for self service BI...)
2- DAX must be carefully developed, or else is very slow, (so the perspective "let's try to see if this works" many times results in slow reports...)
I end with a question, related with the 2nd point:
is there anyway (considering your code or generally speaking) to refer a (previous) column in a table or matrix, to optimize calculations?
It could be like picking the delta you calculated, and using it in a complex calculation like
( row_columnA * row_columnB / row_columnZ) + (row_columnD *delta)
without having to calculate delta it again.
Thanks again, Regards.
- MFelix6 years ago
Super User
Hi Ricardo77 ,
Totally agree with you on the two points you refer, check this post from the great Alberto Ferrari where we defend that DAX is simple, but it is not easy.
https://www.sqlbi.com/blog/alberto/2020/06/20/7-reasons-dax-is-not-easy/
Regarding your question this is possible to have using the DELTA has a measure within a measure or making a temp_table. But if you could give some more information about the context that you need, because using measures depends on context also.