cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CJ_96601
Helper V
Helper V

Measure - If then else

Can someone help me to calculate each record with F as 2 count and M as one count, please refer below. 

 

Record     
      
F     
F     
F     
F     
M     
M     
M     
      
Total count 11    
      
Note:  Each record with F is equivalent to 2 and M is equivalent to 1 
1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @CJ_96601 ,

I have crate an index column first in query editors to count conveniently.

Then you can create a measure like this:

Total count =
CALCULATE (
    COUNT ( 'Table'[Record] ),
    FILTER ( 'Table', 'Table'[Record] = "F" )
) * 2
    + CALCULATE (
        COUNT ( 'Table'[Record] ),
        FILTER ( 'Table', 'Table'[Record] = "M" )
    )

You will get the result:

total count.png

 

Here is the demo, please try it:

PBIX 

 

Best Regards,
Yingjie Li

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

4 REPLIES 4
v-yingjl
Community Support
Community Support

Hi @CJ_96601 ,

I have crate an index column first in query editors to count conveniently.

Then you can create a measure like this:

Total count =
CALCULATE (
    COUNT ( 'Table'[Record] ),
    FILTER ( 'Table', 'Table'[Record] = "F" )
) * 2
    + CALCULATE (
        COUNT ( 'Table'[Record] ),
        FILTER ( 'Table', 'Table'[Record] = "M" )
    )

You will get the result:

total count.png

 

Here is the demo, please try it:

PBIX 

 

Best Regards,
Yingjie Li

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

Thanks. it works as per my requirements

amitchandak
Super User
Super User

@CJ_96601 


you can have column like this and sum
new Column = If(Table[Record]="F",2,1)
or

sumx(values(Table[Record]),If(Table[Record]="F",2,1))
or
sumx(selectcolumns(Table,"ID",Table[record],"_sum",If(Table[Record]="F",2,1)),[_sum])



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Thanks.

 

I want to count the records as follows:

 

   F

   F

   M

 

Based on the below sample.  Total count is 5

Helpful resources

Announcements
Power BI Show Episode 10 Recap

The Power BI Community Show

Watch the playback when Amit Chandak, a Power BI Super User, demos how to use Field Parameters to make reports more dynamic.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Health and Life Sciences Power BI User Group

Health and Life Sciences Power BI User Group

Power BI specialists at Microsoft have created a community user group where customers in the provider, payor, pharma, health solutions, and life science industries can collaborate.

Ignite 2022

What's Next at Microsoft Ignite 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Top Solution Authors