Forum Discussion
Dynamic calculation based on multiple slicer
- Anonymous4 years ago
Hi gjgj111111
I suggest you to combine all XX:PO columns to a same column. In Power BI, we always calculate values from same columns. Then add an Index column in your data model. You can add it directly in your data source or you can add this column by Power Query.
For reference: How to create group index with Power Query or R
You table will look like as below.
Then build a measure.
CNPO = VAR _NPO = SUMX ( FILTER ( 'Table', 'Table'[CF] = "NPO" ), 'Table'[PO] ) VAR _MaxIndex = MAX ( 'Table'[Index] ) VAR _MaxIndexValue = CALCULATE ( SUM ( 'Table'[PO] ), FILTER ( ALL ( 'Table' ), 'Table'[Index] <> 1 && 'Table'[Index] = _MaxIndex && 'Table'[Date] = MAX ( 'Table'[Date] ) ) ) VAR _List = CALCULATETABLE ( VALUES ( 'Table'[PO] ), FILTER ( 'Table', 'Table'[Index] <> _MaxIndex && 'Table'[Index] <> 1 ) ) VAR _Product = IF ( MAX ( 'Table'[Index] ) = 1 || DISTINCTCOUNT ( 'Table'[Index] ) = 2, 1, PRODUCTX ( _List, [PO] ) ) RETURN IF ( ISFILTERED ( 'Table'[CF] ), ( _NPO + _MaxIndexValue * 1000 ) * _Product, BLANK () )Result is as below. By default it will show blank.
If only NPO is selected in slicer 2 & 3-Mar-14 is selected in slicer 1
measure should be CNPO = 760543If NPO and some other valuein slicer 2 (ex. CT) are selected in slicer 2 & 3-Mar-14 in slicer 1is selected
measure should be CNPO = (760543 + (1.02049*1000)) = 761,563.49If NPO and all other value are selected & 27-Nov-14 in slicer 1 is selected
measure should be CNPO = (786863.6115 + (0.154227*1000)) * 0.961114 * 1.004037 * 0.999307 * 0.999554 * 0.999548 * 1.000667 * 1.013536 = 769036.2286Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If you have any ideas or suggestions, please help me.
- Anonymous4 years agoNot applicable
Hi gjgj111111
I suggest you to combine all XX:PO columns to a same column. In Power BI, we always calculate values from same columns. Then add an Index column in your data model. You can add it directly in your data source or you can add this column by Power Query.
For reference: How to create group index with Power Query or R
You table will look like as below.
Then build a measure.
CNPO = VAR _NPO = SUMX ( FILTER ( 'Table', 'Table'[CF] = "NPO" ), 'Table'[PO] ) VAR _MaxIndex = MAX ( 'Table'[Index] ) VAR _MaxIndexValue = CALCULATE ( SUM ( 'Table'[PO] ), FILTER ( ALL ( 'Table' ), 'Table'[Index] <> 1 && 'Table'[Index] = _MaxIndex && 'Table'[Date] = MAX ( 'Table'[Date] ) ) ) VAR _List = CALCULATETABLE ( VALUES ( 'Table'[PO] ), FILTER ( 'Table', 'Table'[Index] <> _MaxIndex && 'Table'[Index] <> 1 ) ) VAR _Product = IF ( MAX ( 'Table'[Index] ) = 1 || DISTINCTCOUNT ( 'Table'[Index] ) = 2, 1, PRODUCTX ( _List, [PO] ) ) RETURN IF ( ISFILTERED ( 'Table'[CF] ), ( _NPO + _MaxIndexValue * 1000 ) * _Product, BLANK () )Result is as below. By default it will show blank.
If only NPO is selected in slicer 2 & 3-Mar-14 is selected in slicer 1
measure should be CNPO = 760543If NPO and some other valuein slicer 2 (ex. CT) are selected in slicer 2 & 3-Mar-14 in slicer 1is selected
measure should be CNPO = (760543 + (1.02049*1000)) = 761,563.49If NPO and all other value are selected & 27-Nov-14 in slicer 1 is selected
measure should be CNPO = (786863.6115 + (0.154227*1000)) * 0.961114 * 1.004037 * 0.999307 * 0.999554 * 0.999548 * 1.000667 * 1.013536 = 769036.2286Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- gjgj1111114 years agoFrequent Visitor
Hi Mr. RicoZhou
I have some problem with this model.
If NPO and some other value in slicer 2 (ex. only AT) are selected in slicer 2 & 27-Nov-14 in slicer 1 is selected
measure should be CNPO = (786863.6115+(0*1000)) * (0.961114)BUT the measure seems to be CNPO = (786863.6115 + (0.961114*1000)) * 1
which is a wrong calculation because AT (0.961114) becomes _MaxValueIndex (instead of CT(0.154227) as CT is unselected) (If CT is unselected, the value has to be 0) (Unselected values in slicer 2 are equal 1 except CT)
Thanks a lot for your support and any help is appreciated!