Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

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!!!! 

 
1 ACCEPTED SOLUTION

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:
a1.png

Best Regards
Allan

 

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

View solution in original post

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

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

3.png

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.

1.png

2.png

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

 

Capture.PNG

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:
a1.png

Best Regards
Allan

 

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

Greg_Deckler
Super User
Super User

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.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
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. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.