Forum Discussion

netanel's avatar
netanel
Icon for Post Prodigy rankPost Prodigy
4 years ago
Solved

Gross + If

Hi All!

 

I have this measure:

Gross USD=CALCULATE( DIVIDE( SUM( 'DB 2021'[Gross USD] ), COUNTROWS( 'Date' ) ),

   keepfilters(  'Date'[Date] < TODAY()))

 

And I want to put the following condition into it:

If the Source = "Amn" then bring me both Gross USD and Fee
Otherwise just bring me Gross USD

 

 

 

 

 

 

 

 

 

Thanks for the helpers!

  • Hi netanel ,

     

    You can try below code:-

    Gross USD =
    IF (
        SELECTEDVALUE ( 'Table'[Source] ) = "Amn",
        CALCULATE (
            DIVIDE (
                ( SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee] ) ),
                COUNTROWS ( 'Date' )
            ),
            KEEPFILTERS ( 'Date'[Date] < TODAY () )
        ),
        CALCULATE (
            DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
            KEEPFILTERS ( 'Date'[Date] < TODAY () )
        )
    )

     

    Thanks,

    Samarth

4 Replies

  • ValtteriN's avatar
    ValtteriN
    Icon for Community Champion rankCommunity Champion

    Hi,

    You can include IF to your Fee measure. So something like this
    Measure = IF(SELECTEDVALUE('Table'[Source])<>"Amn",BLANK(),[FEE])

    With this the measure will display blank if the Source is something besides Amn. I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!

    • netanel's avatar
      netanel
      Icon for Post Prodigy rankPost Prodigy

      Hi ValtteriN 

       

      I'm really getting close to the result in the idea you proposed
      Only at the end of the formula:
      Measure = IF (SELECTEDVALUE ('Table' [Source]) <> "Amn", BLANK (), [FEE])

      What is marked in pink is a column in a table and not a formula
      How to bring it?

      • ValtteriN's avatar
        ValtteriN
        Icon for Community Champion rankCommunity Champion

        Hi,

        Then you can just use the same logic with that column:
        Measure = IF (SELECTEDVALUE ('Table' [Source]) <> "Amn", BLANK (), SELECTEDVALUE('Table'[FEE]))

  • Samarth_18's avatar
    Samarth_18
    Icon for Community Champion rankCommunity Champion

    Hi netanel ,

     

    You can try below code:-

    Gross USD =
    IF (
        SELECTEDVALUE ( 'Table'[Source] ) = "Amn",
        CALCULATE (
            DIVIDE (
                ( SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee] ) ),
                COUNTROWS ( 'Date' )
            ),
            KEEPFILTERS ( 'Date'[Date] < TODAY () )
        ),
        CALCULATE (
            DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
            KEEPFILTERS ( 'Date'[Date] < TODAY () )
        )
    )

     

    Thanks,

    Samarth