1

I want to calculate the running count of each value based on column SF ID. In Excel power query , I am trying to apply countif in the following table but i cant find this equation here.

enter image description here

I would like to get the same result in excel Power query. Can you please advise.

enter image description here

i've used to group the date like below but this isn't the result that i want.

enter image description here

4
  • Lots of examples of countif() and countifs() on here, this is but one: stackoverflow.com/q/33358534/4961700 Commented Aug 19, 2022 at 7:38
  • i know how to use countif as an equation, but i need to use it to calculate something in power query, i can't find a way to calculate what i want in custom column in power query. Commented Aug 19, 2022 at 7:43
  • So will powerquery open a specific file? make a template then get powerquery to use it. Commented Aug 19, 2022 at 7:46
  • yes, i extract specific data from a master excel sheet then i want to count the occurrences of the column SF ID Commented Aug 19, 2022 at 7:51

3 Answers 3

3
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcy5CQAwDASwXVwHzm+eWUz2XyOQzuBWhTJJIFCWoEFizCx0R5JCi+pXgxW1rw5vhkA0w8RshoXVDBu7GQ5OUad7Hw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"SF ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"SF ID", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"SF ID"}, {{"Count", each _, type table [Date=nullable date, SF ID=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count], "Index", 1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Date", "SF ID", "Index"}, {"Date", "SF ID", "Index"})
in
    #"Expanded Custom"
Sign up to request clarification or add additional context in comments.

2 Comments

many thanks, it's working but there a small issue, the rows repeated many times , could you advice why this happen
@MahmoudBadr this is the result as you wanted expected result picture in your question. If you need something else, revise your question.
0
CALCULATE(
    COUNTROWS(tbl)
    ,ALLEXCEPT(tbl,tbl[SF ID])
    ,tbl[Date]<=MAX(tbl[Date])
)
    

5 Comments

i used this command but i found this error message (Expression.Error: The name 'CALCULATE' wasn't recognized. Make sure it's spelled correctly.)
This is a DAX command, you can't use it in Power Query.
is there any way to calculate what i want i power query?
I'm not familiar with M. It was a DAX tag, so I added. Why don't you want to add calculated column to the table in the model? Seems it would be easer and fast enough.
@Tyler2P, thank you for the comment. I cant get the point what is the reason for M (may be it is) for the case. The measure itself and approach to solve the problem are very plain and simple, I don't see what to comment ).
0

If I understood correctly, try this :

Select the two columns Date and SFID an make a groupby.

enter image description here enter image description here

EDIT :

Open the Advanced Editor and put the code below :

 let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"SF ID", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"SF ID", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"SF ID"}, {{"AllData", each _, type table [Date=nullable datetime, SFID=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Status", each Table.AddIndexColumn([AllData], "Status", 1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Status", {"Date", "Status"}, {"Date", "Status"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"AllData"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Date", "SF ID", "Status"})
in
    #"Reordered Columns"

Make sure that your table is named "Table1". Otherwise, you have to rename it.

2 Comments

i used this option but the data count as the above screen shoot, i've eddied my question to see the issue
So this is not a countif issue ! Take a look at the EDIT I added to my answer. If this is still not the result you're looking for, you may need to give a sample data other than a simple screenshot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.