Running Count of Answers

horrellbt01

Board Regular
Joined
Mar 15, 2010
Messages
68
I have a list of questions and answers by date. The answers are text, so I need to do a running COUNT rather than total.

Here is an example of my raw data.

Answer DateWeek NumberAnswer
1/1/20201Red
1/1/20201Blue
1/8/20202Green
1/8/20202Green
1/15/20203Blue
1/15/20203Blue
1/15/20203Green


What I am looking to return is something like this using the new measure
AnswerWeek 1Week 2Week 3
Blue13
Red1
Green23
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Answer DateWeek NumberAnswerAnswer123
01/01/20201RedBlue102
01/01/20201BlueGreen021
08/01/20202GreenRed100
08/01/20202Green
15/01/20203Blue
15/01/20203Blue
15/01/20203Green

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    TDC = Table.DuplicateColumn(Source, "Week Number", "Week Number - Copy"),
    RC = Table.RemoveColumns(TDC,{"Answer Date"}),
    Pivot = Table.Pivot(Table.TransformColumnTypes(RC, {{"Week Number - Copy", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(RC, {{"Week Number - Copy", type text}}, "en-GB")[#"Week Number - Copy"]), "Week Number - Copy", "Week Number", List.Count)
in
    Pivot

or with Pivot Table
ptbl.png
 
Last edited:
Upvote 0
or like this
AnswerWeek 1Week 2Week 3
Blue12
Green21
Red1

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Prefix = Table.TransformColumns(Source, {{"Week Number", each "Week " & Text.From(_, "en-GB"), type text}}),
    Group = Table.Group(Prefix, {"Answer", "Week Number"}, {{"Count", each Table.RowCount(_), type number}}),
    Sort = Table.Sort(Group,{{"Week Number", Order.Ascending}}),
    Pivot = Table.Pivot(Table.TransformColumnTypes(Sort, {{"Week Number", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(Sort, {{"Week Number", type text}}, "en-GB")[#"Week Number"]), "Week Number", "Count", List.Sum)
in
    Pivot
 
Upvote 0
or like this
AnswerWeek 1Week 2Week 3
Blue12
Green21
Red1

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Prefix = Table.TransformColumns(Source, {{"Week Number", each "Week " & Text.From(_, "en-GB"), type text}}),
    Group = Table.Group(Prefix, {"Answer", "Week Number"}, {{"Count", each Table.RowCount(_), type number}}),
    Sort = Table.Sort(Group,{{"Week Number", Order.Ascending}}),
    Pivot = Table.Pivot(Table.TransformColumnTypes(Sort, {{"Week Number", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(Sort, {{"Week Number", type text}}, "en-GB")[#"Week Number"]), "Week Number", "Count", List.Sum)
in
    Pivot
These solutions work, but I am not working in excel for this project. I am looking for a solution in Power BI
 
Upvote 0
Sorry - That will not work for what I need, the above is just an example. I need this as a measure to use within Power BI and my different datasets. If all I needed was a pivot table, you are correct. With this being a power BI forum I didn't think I needed to include that detail.


After sleeping on it and fresh coffee this morning I was able to figure it out. Here is my solution:

Running Count of Answers =
CALCULATE(
DISTINCTCOUNT('page'[TDLINX ID]),
FILTER(
ALLSELECTED('page'[Week of Year]),
ISONORAFTER('page'[Week of Year], MAX('page'[Week of Year]), DESC)
)
)
 
Upvote 0
Solution
It's nice that you worked it out
have a nice day

btw.

Power BI

Business Intelligence Tools: Power Pivot, Power View, Power Query, DAX Formulas
 
Upvote 0

Forum statistics

Threads
1,223,753
Messages
6,174,307
Members
452,554
Latest member
Louis1225

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