Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

count rows and filter

Hi Everyone, 

 

I have a date table and a table1 below , in my measure, I want to show # of wins of the largest year when the slicer is not selected, that I used the measure below: 

 

 

FYRegioninbound/outboundindustrystageUS_fee
FY 2018Great LakesOutboundFinancial ServicesWin18000
FY 2018SoutheastOutboundFinancial ServicesWin150000
FY 2017NortheastOutboundBusiness Professional ServicesWin141000
FY 2020Great LakesInboundIndustrial ProductsWithdrawal 
FY 2020NortheastOutboundGovernmentWithdrawal 
FY 2020Great LakesInboundBusiness Professional ServicesWithdrawal 
FY 2016Great LakesInboundOtherWithdrawal 
FY 2019Great LakesOutboundManufacturing  
FY 2019SoutheastInboundTechnologyLoss 

 

 

 

win count = 
var __win = 
CALCULATE(COUNTROWS('Table1'),
ALL(FY[FY]),
'Table1',
    'Table1'[Stage]="Win")
return 
IF(SELECTEDVALUE(FY[FY],"FY 9000")<=MAX(FY[FY])
    ,CALCULATE(__win),
    CALCULATE(COUNTROWS(Table1),
                FILTER(ALL(FY[FY]),MAX(Table1[FY])=FY[FY]),
                Table1[stage]="Win"
    ))

 

 

 

 However it's not giving me the right answer... can Anyone help me with it?

 

Thanks!!!! 

 
  • Hi, Anonymous 

    You can create a measure as follows.

     

    win count = 
    var  m = MAX('Table'[FY])  
    return
    IF (
        ISFILTERED ( 'FY'[FY] ),
        CALCULATE (
            COUNTROWS ( 'Table' ),
            ALLSELECTED ( 'Table' ),
            'Table'[Stage] = "Win"
        ),
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[FY] = m
            ),
            'Table'[Stage] = "Win"
        )
    )

     

     

    Result:


    Best Regards
    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion
    Not entirely sure I understand what you are going for. HASONEVALUE could be used to test whether something has been selected in a slicer. You could also COUNT or COUNTROWS for your column and compare that with the count of ALL that column or table. If you want the largest year, use MAX or MAXX? Depends on what you mean by largest.
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Greg_Deckler , 

       

      thanks for responding. the largest year would be the largest year of the row. I want to achieve something like this: if the slicer is selected, it returns the result to whatever the year selected (say if I select FY 2016, it returns 1 and if select FY 2020, it returns 3); otherwise it returns the largest year of the row (FY 2020, and the row count is 3).  that's why I used selected value to try to achieve this. However, I don't know what I did wrong that its' not retuning the correct result. 

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

    Hi, Anonymous 

     

    Based on your description, I created data to reproduce your scenario.

    With your measure, It works well while the slicer is not selected because there is no win in the largest year 2020. The result is as follows.

     

    The corresponding value of measure for FY2016, FY2020 is 0, 0.

    About your reply, maybe there is something wrong in the sample data. Whether the value of stage in FY2020 and FY2016 would be ‘Win’. If so, the result is as below.

     

    The corresponding value of measure for FY2016, FY2017, FY2018, FY2019, FY2020 is 1, 1 , 2, 0, 3.

     

    If I misunderstand your thought, please show me your sample data and expected output. I am glad to solve the problem for you.

    Best Regards,

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-alq-msft , 

       

      Here's the data I have :

       

      FYRegioninbound/outboundindustrystageUS_fee
      FY 2020Great LakesOutboundTechnologyWin20000
      FY 2020NortheastOutbound Withdrawal 
      FY 2019Great LakesInbound Withdrawal 
      FY 2019Great LakesOutboundManufacturing  
      FY 2019WestOutboundOtherWin 
      FY 2019SoutheastOutboundTechnologyWin 
      FY 2019Great LakesOutboundPrivate EquityLoss 
      FY 2019Great LakesOutboundIndustrial ProductsWithdrawal 
      FY 2018NortheastOutboundIndustrial ProductsWithdrawal250000
      FY 2018CentralOutboundIndustrial ProductsWin76000
      FY 2018CentralOutboundBusiness Professional ServicesWin21000
      FY 2018NortheastOutboundNonprofitWin101750
      FY 2017Great LakesOutboundTechnologyWin10000
      FY 2017SoutheastOutboundBusiness Professional ServicesWin9500
      FY 2017WestOutbound Loss650000
      FY 2017NortheastOutboundBusiness Professional ServicesWin120000
      FY 2017SoutheastOutboundIndustrial ProductsWin99000
      FY 2016WestOutboundIndustrial ProductsWin124500
      FY 2016WestOutboundConsumer ProductsWin46000
       CentralInbound   
       NortheastUS to USFinancial Institutions  

       

      when I calculated the win count, yes, it's giving me the correct number. However when I want to group it by Industry , it's not calculated right, see the screenshot below. but when there's slicer selected, the win count by industry is correct. 

       

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

        Hi, Anonymous 

        You can create a measure as follows.

         

        win count = 
        var  m = MAX('Table'[FY])  
        return
        IF (
            ISFILTERED ( 'FY'[FY] ),
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLSELECTED ( 'Table' ),
                'Table'[Stage] = "Win"
            ),
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    'Table'[FY] = m
                ),
                'Table'[Stage] = "Win"
            )
        )

         

         

        Result:


        Best Regards
        Allan

         

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.