Forum Discussion

hoa3nok7's avatar
hoa3nok7
Frequent Visitor
4 years ago
Solved

Switching Signs in Power BI

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.

 

FYPeriodGroupingAmountFlipped Amount
20211A9-9
20211B3-3
20211C2020
20211D1515
20201A4-4
20201B16-16
20201C-21-21
20201D1313
20191A15-15
20192B14-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 YTDPFY YTD
A3 (Flipped)2 (Flipped)
B-5 (Flipped)-4 (Flipped)
C7 (Not flipped)6 (Not flipped)
D9 (Not Flipped)8 (Not Flipped)
Total -18-16

 

However, the current matrix I have is like below

Grouping CFY YTD PFY YTD 
A32
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"
)
)

  • 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.  

     

    GroupingFlip Behavior
    A-1
    B-1
    C1
    D1
  • 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.

5 Replies

  • 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.  

     

    GroupingFlip Behavior
    A-1
    B-1
    C1
    D1
  • 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.

    • hoa3nok7's avatar
      hoa3nok7
      Frequent Visitor

      v-angzheng-msft 

       

      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.



      • v-angzheng-msft's avatar
        v-angzheng-msft
        Community Support

        Hi, hoa3nok7 

         

        How about using these two functions?

        HASONEVALUE

        ISFILTERED

        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.