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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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.


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.