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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
gunther15
Frequent Visitor

HIt Rate Calculation

Hi,

 

I have a hit range filter of 1 month, 3 months, 6 month, 9 month, and 12 months.  I need to filter out the total trans amount for each one of those to get the hit rate.  I also have the total quoted amount for each month so like January 2020 etc.  So for 1 month I need the 1 month hit range trans amount divided by the quoted amount in that specific month.  For 3 months I would need 1 and 3 Months added together divided by the total quoted amount for that specific month and etc.  What caculations would I needed to be done to get this?

gunther15_0-1665000444419.png

Here is the data for January 2020.

 

Thank you

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi  @gunther15 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Add a custom column as below in Power Query Editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY47CgMxDESvYlwvQj/L9iHCHsC4SyBFyMIm9yeyXSxEqBAzjxm1FuM21siEEse+tUjhdry/T1cVURiK+ClMVpbNy/8MVZkNWP0kQqQ/Ihxn2F/3xzn9ipYgjzAqaLbK5Aor4gOuDzhrxQnYBaRcNUOabVyNbQL1ArIQM2gaALI/FHv/AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Hit Rate Range" = _t, #"Total Trans Amount" = _t, #"Total Quoted" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hit Rate Range", type text}, {"Total Trans Amount", type number}, {"Total Quoted", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Month Range", each if [Hit Rate Range]="" then 0 
else if  Text.Contains ([Hit Rate Range],"or Older") then 999 else  Text.Select([Hit Rate Range],{"0".."9"})),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Month Range", Int64.Type}})
in
    #"Changed Type1"

yingyinr_0-1665047625519.png

2. Create a measure as below:

Hit Rate = 
VAR _selmrange =
    SELECTEDVALUE ( 'Table'[Month Range] )
VAR _sumoftquoted =
    SUM ( 'Table'[Total Quoted] )
VAR _cultramount =
    CALCULATE (
        SUM ( 'Table'[Total Trans Amount] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Month Range] <= _selmrange )
    )
RETURN
    DIVIDE ( _cultramount, _sumoftquoted )

yingyinr_1-1665047683000.png

If the above one can't help you get the desired result, please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi  @gunther15 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Add a custom column as below in Power Query Editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY47CgMxDESvYlwvQj/L9iHCHsC4SyBFyMIm9yeyXSxEqBAzjxm1FuM21siEEse+tUjhdry/T1cVURiK+ClMVpbNy/8MVZkNWP0kQqQ/Ihxn2F/3xzn9ipYgjzAqaLbK5Aor4gOuDzhrxQnYBaRcNUOabVyNbQL1ArIQM2gaALI/FHv/AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Hit Rate Range" = _t, #"Total Trans Amount" = _t, #"Total Quoted" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hit Rate Range", type text}, {"Total Trans Amount", type number}, {"Total Quoted", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Month Range", each if [Hit Rate Range]="" then 0 
else if  Text.Contains ([Hit Rate Range],"or Older") then 999 else  Text.Select([Hit Rate Range],{"0".."9"})),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Month Range", Int64.Type}})
in
    #"Changed Type1"

yingyinr_0-1665047625519.png

2. Create a measure as below:

Hit Rate = 
VAR _selmrange =
    SELECTEDVALUE ( 'Table'[Month Range] )
VAR _sumoftquoted =
    SUM ( 'Table'[Total Quoted] )
VAR _cultramount =
    CALCULATE (
        SUM ( 'Table'[Total Trans Amount] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Month Range] <= _selmrange )
    )
RETURN
    DIVIDE ( _cultramount, _sumoftquoted )

yingyinr_1-1665047683000.png

If the above one can't help you get the desired result, please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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