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.
Hi everyone,
My data is like this. Each group has corresponding amount and I only flip the amount for group A and B, but keep the sign for C and D the same.
FY | Period | Grouping | Amount | Flipped Amount |
2021 | 1 | A | 9 | -9 |
2021 | 1 | B | 3 | -3 |
2021 | 1 | C | 20 | 20 |
2021 | 1 | D | 15 | 15 |
2020 | 1 | A | 4 | -4 |
2020 | 1 | B | 16 | -16 |
2020 | 1 | C | -21 | -21 |
2020 | 1 | D | 13 | 13 |
2019 | 1 | A | 15 | -15 |
2019 | 2 | B | 14 | -14 |
Below is the Matrix I want to achieve - the total should be equal to -A+(-B)-C-D; this is the reason why I used the flipped amount column to generate the CFY YTD and PFY YTD measures.
Grouping | CFY YTD | PFY YTD |
A | 3 (Flipped) | 2 (Flipped) |
B | -5 (Flipped) | -4 (Flipped) |
C | 7 (Not flipped) | 6 (Not flipped) |
D | 9 (Not Flipped) | 8 (Not Flipped) |
Total | -18 | -16 |
However, the current matrix I have is like below
Grouping | CFY YTD | PFY YTD |
A | 3 | 2 |
B | -5 | -4 |
C | -7 | -6 |
D | -9 | -8 |
Total | -18 | -16 |
The dax formula I am using is in below. Can anyone please pinpoint a direction?
CFY YTD:=
CALCULATE (
SUM ( 'Table1'[Flipped Amount]),
FILTER (
'Table1',
'Table1'[FISCAL_YEAR] = [Selected Fiscal Year]
),
FILTER (
'Table1',
'Table1'[PERIOD] <= [Selected Period]
),
FILTER (
'Table1',
'Table1'[Grouping] = "A"
|| 'Table1'[Grouping] = "B"
)
)
-CALCULATE (
SUM ( 'Table1'[Flipped Amount]),
FILTER (
'Table1',
'Table1'[FISCAL_YEAR] = [Selected Fiscal Year]
),
FILTER (
'Table1',
'Table1'[PERIOD] <= [Selected Period]
),
FILTER (
'Table1',
'Table1'[Grouping] = "C"
|| 'Table1'[Grouping] = "D"
)
)
Solved! Go to Solution.
Hello - I recommend you add a mapping table that indicates the desired flip behavior and then relate it to the fact table and incorporate it into your calculation.
Grouping | Flip Behavior |
A | -1 |
B | -1 |
C | 1 |
D | 1 |
Hi, @hoa3nok7
In this case, I think the flipped amount column is not necessary.
You can use the ISINSCOP function to calculate the total separately.
Modify the above measures as follows:
Measure =
VAR _SUM_AB =
CALCULATE (
SUM ( 'Table1'[Amount] ),
FILTER ( 'Table1', 'Table1'[FISCAL_YEAR] = [Selected Fiscal Year] ),
FILTER ( 'Table1', 'Table1'[PERIOD] <= [Selected Period] ),
FILTER ( 'Table1', 'Table1'[Grouping] = "A" || 'Table1'[Grouping] = "B" )
)
VAR _SUM_CD =
CALCULATE (
SUM ( 'Table1'[Amount] ),
FILTER ( 'Table1', 'Table1'[FISCAL_YEAR] = [Selected Fiscal Year] ),
FILTER ( 'Table1', 'Table1'[PERIOD] <= [Selected Period] ),
FILTER ( 'Table1', 'Table1'[Grouping] = "C" || 'Table1'[Grouping] = "D" )
)
VAR _SUM_ALL =
CALCULATE (
SUM ( 'Table1'[Amount] ),
FILTER ( 'Table1', 'Table1'[FISCAL_YEAR] = [Selected Fiscal Year] ),
FILTER ( 'Table1', 'Table1'[PERIOD] <= [Selected Period] )
)
RETURN
IF (
ISINSCOPE ( 'Table'[Grouping] ),
// 1,
- ( _SUM_AB ) + _SUM_CD,
// 2
- ( _SUM_ALL )
)
If this doesn't work, could you please consdier sharing more details about it and posting expected result so it is clear on what needs to be implemented? And It would be great if there is a sample file without any sesentive information here. It makes it easier to give you a solution.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @hoa3nok7
In this case, I think the flipped amount column is not necessary.
You can use the ISINSCOP function to calculate the total separately.
Modify the above measures as follows:
Measure =
VAR _SUM_AB =
CALCULATE (
SUM ( 'Table1'[Amount] ),
FILTER ( 'Table1', 'Table1'[FISCAL_YEAR] = [Selected Fiscal Year] ),
FILTER ( 'Table1', 'Table1'[PERIOD] <= [Selected Period] ),
FILTER ( 'Table1', 'Table1'[Grouping] = "A" || 'Table1'[Grouping] = "B" )
)
VAR _SUM_CD =
CALCULATE (
SUM ( 'Table1'[Amount] ),
FILTER ( 'Table1', 'Table1'[FISCAL_YEAR] = [Selected Fiscal Year] ),
FILTER ( 'Table1', 'Table1'[PERIOD] <= [Selected Period] ),
FILTER ( 'Table1', 'Table1'[Grouping] = "C" || 'Table1'[Grouping] = "D" )
)
VAR _SUM_ALL =
CALCULATE (
SUM ( 'Table1'[Amount] ),
FILTER ( 'Table1', 'Table1'[FISCAL_YEAR] = [Selected Fiscal Year] ),
FILTER ( 'Table1', 'Table1'[PERIOD] <= [Selected Period] )
)
RETURN
IF (
ISINSCOPE ( 'Table'[Grouping] ),
// 1,
- ( _SUM_AB ) + _SUM_CD,
// 2
- ( _SUM_ALL )
)
If this doesn't work, could you please consdier sharing more details about it and posting expected result so it is clear on what needs to be implemented? And It would be great if there is a sample file without any sesentive information here. It makes it easier to give you a solution.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you Zeon for your response. It looks like the ISINSCOPE does not work when connection type is LIVE (SSAS tabular). Do you know any equivalent way that I can avoid it? Thank you.
Hi, @hoa3nok7
How about using these two functions?
RETURN IF (HASONEVALUE ( 'Table'[Grouping] ),1,2)
RETURN IF (ISFILTERED( 'Table'[Grouping] ),1,2)
I seem to be able to use this function in SSAS. Am i missing something?
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I can't tell how you are getting the values in the matrix you want to achieve from the data you provided.
Hello - I recommend you add a mapping table that indicates the desired flip behavior and then relate it to the fact table and incorporate it into your calculation.
Grouping | Flip Behavior |
A | -1 |
B | -1 |
C | 1 |
D | 1 |
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.