Divide filtered count by the total count

horrellbt01

Board Regular
Joined
Mar 15, 2010
Messages
68
I am having a hard time writing this measure.

I have a table called Stores
In that table I have a column named TM and a column named "StoreType"

I need a measure that divides the number of times the word "open" appears in the TM column by the count of the specific store type.

Example:

StoreTypeTMDesired Result
AOpen 9-5Store TypeOpen %
AClosedA
50%​
BOpen 10-2B
75%​
BRenovationC
50%​
BOpen 7-4
COpen
COpen during construction
CClosed permanently
CUnknown
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
how about the attached?

FYI for B your result should be 66.6% as it open 2 out 3

You'll need to change the formula for B and C in your criteria for the countif/countifs as shown only shows A

1613660271221.png
 
Last edited:
Upvote 0
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"StoreType", type text}, {"TM", type text}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter([TM], " ", 0), type text),
#"Grouped Rows" = Table.Group(#"Inserted Text Before Delimiter", {"StoreType", "Text Before Delimiter"}, {{"Count", each Table.RowCount(_), type number}, {"MyData", each _, type table}}),
#"Expanded MyData" = Table.ExpandTableColumn(#"Grouped Rows", "MyData", {"TM"}, {"TM"}),
#"Grouped Rows1" = Table.Group(#"Expanded MyData", {"StoreType"}, {{"Count", each Table.RowCount(_), type number}, {"MYData", each _, type table}}),
#"Expanded MYData" = Table.ExpandTableColumn(#"Grouped Rows1", "MYData", {"Text Before Delimiter", "Count", "TM"}, {"Text Before Delimiter", "Count.1", "TM"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded MYData",{"StoreType", "TM", "Text Before Delimiter", "Count.1", "Count"}),
#"Filtered Rows" = Table.SelectRows(#"Reordered Columns", each ([Text Before Delimiter] = "Open")),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Percentage", each [Count.1]/[Count]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Percentage", Percentage.Type}}),
#"Grouped Rows2" = Table.Group(#"Changed Type1", {"StoreType", "Percentage"}, {{"Final Data", each _, type table}}),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows2",{"Final Data"})
in
#"Removed Columns"

Not a measure but M-Code... (Extracted from advanced editor)

Table1 is the name of the table which is containing the first two columns of your example. Columns [StoreType] and [TM]
(not exactly a DAX but rather an alternative. and might take a large amount of computation time if used in a large data set)
 
Upvote 0
If you want a more elegant approach.

You would need to do the ff:
1.)Create a Query containing your table which has a custom column containing the ff:
=(Text.Contains([TM],"Open"))
This should return a binary (True/False) >then manually change type into a number > then group and add up the binary

2.)Create a new Query which is grouped and count rows.
This should return a table which consists of the number of counts of A, B, and C.

3.)Merge Query1 and Query 2 using Left outer tada! You have your total of open stores and total of number of stores. Just add Metric or Add a new column.

I hope this helps.
 
Upvote 0

Forum statistics

Threads
1,223,738
Messages
6,174,207
Members
452,551
Latest member
croud

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top