Forum Discussion
EARLIER function in M/Query Editor
- 8 years ago
HI bullius,
Yes it is possible to do that in M.
To sum up group by your id and add an index.
You can add this code into your steps:
#"Grouped Rows" = Table.Group(#"Promoted Headers", {"ID"}, {{"Count", each Table.AddIndexColumn(_, "Index", 1, 1), type table}})Hope it helps...
Ninter
Hi bullius,
You are absolutely right. You can rank and then pivot the column to achieve what you need.
Here is a sample pbix which showcases this.
Prateek Raina
- bullius8 years agoHelper V
Thanks prateekraina. My actual dataset is much larger than the example and does not include a Rank field. My question is how do I create one? I would use the EARLIER function in DAX to make sure the ranking restarts with each new ID, but can't find an alternative in M.
- Interkoubess8 years agoSolution Sage
HI bullius,
Yes it is possible to do that in M.
To sum up group by your id and add an index.
You can add this code into your steps:
#"Grouped Rows" = Table.Group(#"Promoted Headers", {"ID"}, {{"Count", each Table.AddIndexColumn(_, "Index", 1, 1), type table}})Hope it helps...
Ninter
- prateekraina8 years agoMemorable Member
Hi bullius,
Interkoubess is absolutely right. I haved added his step in the same pbix.
Prateek Raina
- alfranco177 years agoAdvocate I
Hi Patreek.
I have the same question. If you have it at hand, would you please repost your pbix?
Thank you.
Armando.
- Ashish_Mathur7 years agoSuper User
Hi,
Share some data and show the expected result.
- alfranco177 years agoAdvocate I
Thanks for your reply, Ashish.
This is what I have:
Name Date Alice 2019-01-01 Alice 2019-01-03 Alice 2019-01-14 John 2019-01-03 John 2019-01-12 let Source = #table( type table[Name=text, #"Date"=date], { {"Alice",#date(2019,1,1)},{"Alice",#date(2019,1,3)}, {"Alice",#date(2019,1,14)}, {"John",#date(2019,1,12)}, {"John",#date(2019,1,3)} } ) in SourceAnd here is what I need. I want to know the number of the visit by date.
Name Date Visit Alice 2019-01-01 1 Alice 2019-01-03 2 Alice 2019-01-14 3 John 2019-01-03 1 John 2019-01-12 2 I was able to get this using DAX, but I would like to have it there in the query.
Visit = CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( ALL ( 'Table' ), 'Table'[Name] = EARLIER ( 'Table'[Name] ) && 'Table'[Date] <= EARLIER ( 'Table'[Date] ) ) )Thanks.
Armando.