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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mgrayTCB
Helper III
Helper III

Identify which Month of Sales (first, second,.... 12th etc)

 

I am trying to add a colum to a table that identifiles which month (first, second, third, or fourth) the amount represents by ID. I am trying to return the Result column below so I can filter out IDs and sales from first and second months of sales (or whatever early activity thereis in earlist months of the IDs existance). 

 

IDMonthAmountResult
11/31/2024           224.004
112/31/2023              91.003
111/30/2023              86.002
110/31/2023           141.001
23/31/2023           258.001
24/30/2023              52.002
25/31/2023           243.003
312/31/2023           104.001
31/31/2024           172.002
42/28/2023           193.004
41/31/2023           232.003
412/31/2022           136.002
411/30/2022           119.001

 

I am not even sure where to start with this. Any help would be appreciated.

1 ACCEPTED SOLUTION

Hi,

This calculated column formula works

Column = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[fact[Property Id]]]=EARLIER(Data[fact[Property Id]]])&&Data[fact[Month]]]<=EARLIER(Data[fact[Month]]])&&Data[fact[Amount Type]]]=EARLIER(Data[fact[Amount Type]]])))

Hope this helps.

Ashish_Mathur_0-1708739106183.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
sayaliredij
Super User
Super User

Hi @mgrayTCB 

 

Please use following formula for new column

 

Ranking = RANKX(FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[ID] = EARLIER ( 'Table (2)'[ID] ) ),'Table (2)'[Month],,ASC,Dense)
 

Thanks and Regards,

Sayali

Please mark the question solved when done and consider giving a thumbs up if posts are helpful!! 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




wini_R
Resolver IV
Resolver IV

Hi @mgrayTCB,

 

You can check if the following query helps with your task. Just paste the code in the advanced editor in power query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdG9DsIgEAfwVzHMjdwXlY4mLg4+AenuYrvU9/c0LeUa8BYg98ufr5Tc/eY695in5anj9TW/p8WNXXKoS/SMnoBE56e9iOQMsCtaGVumNaCBmgd1GHsDoZ6IkvNIO1xXFGKppLlpoNKFRprwpvjPZRHEsPrL4SVv+e2Qp1jLGrhU2DgYm6x8MDqEcW/Y9gdHhsOPjR8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Promoted Headers", {{"Month", type date}}, "en-US"),
    #"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Amount", type number}, {"ID", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"tab3", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "tab4", each Table.AddIndexColumn(
  Table.Sort([tab3],{{"Month", Order.Ascending}}),
  "result", 1, 1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"tab4"}),
    #"Expanded tab4" = Table.ExpandTableColumn(#"Removed Other Columns", "tab4", {"ID", "Month", "Amount", "result"}, {"ID", "Month", "Amount", "result"})
in
    #"Expanded tab4"

 Outcome:

wini_R_0-1708639471317.png

 

Thank you. Is there a way to do something like that using add column in DAX?

I was thinking a rank of dates for each ID but I am not sure how to do it.

An alternative using RANK function:

 

resultDAX = 
RANK(
    DENSE,
    ORDERBY(tab2[ID], ASC, tab2[Month], ASC),
    PARTITIONBY(tab2[ID])
)

 

This is helpful but my table is a bit more complicated than I orginally posted. I tried using

 DISTINCT(SELECTCOLUMNS(fact,"_id",fact[Property Id],"_mo",fact[Month])) to create a virtual table of unique combinations of ID and Month to then run the rank logic on but I ended up with all 1s.

 

Below is an excerpt of the table. It is financal income statement data for over 150 property IDs over 5 years (at monthly resolution). each recored represents a line in the income statement for a property in a month for a particular line for either budget or actual. All I care about is knowing if it is the first, second, third, etc month of operations so that I can filter out the early months and get a better representation of stabilized operations.

 

fact[Property Id]fact[Account Id]fact[Month]fact[Amount Type]fact[Amount]
1476832/28/2024Budget156
1476831/31/2024Budget111
14768312/31/2023Budget197
14768311/30/2023Budget173
14768310/31/2023Budget112
1476839/30/2023Budget123
4836832/28/2024Budget180
4836831/31/2024Budget153
48368312/31/2023Budget166
48368311/30/2023Budget192
48368310/31/2023Budget104
4836839/30/2023Budget176
4836838/31/2023Budget110
4836837/31/2023Budget187
1476832/28/2024Actual169
1476831/31/2024Actual174
14768312/31/2023Actual111
14768311/30/2023Actual118
14768310/31/2023Actual197
1476839/30/2023Actual167
4836832/28/2024Actual135
4836831/31/2024Actual102
48368312/31/2023Actual187
48368311/30/2023Actual109
48368310/31/2023Actual141
4836839/30/2023Actual127
4836838/31/2023Actual102
4836837/31/2023Actual130

Can you please also include an extra column with expected result? I'm a bit confused now what we need to get here 😉

See below with an expected result column. Regardless of whether the record is a budget item or an actual item I just want to know for each property ID which ordered month the data represents. 

 

The oldest date for a particular property ID is considered its first month of operations.

 

fact[Property Id]fact[Account Id]fact[Month]fact[Amount Type]fact[Amount]Expected Result (ordered month of operations)
1476832/28/2024Budget1956
1476831/31/2024Budget1685
14768312/31/2023Budget1694
14768311/30/2023Budget1693
14768310/31/2023Budget1722
1476839/30/2023Budget1651
4836832/28/2024Budget1688
4836831/31/2024Budget1737
48368312/31/2023Budget1196
48368311/30/2023Budget1605
48368310/31/2023Budget1034
4836839/30/2023Budget1473
4836838/31/2023Budget1402
4836837/31/2023Budget1731
1476832/28/2024Actual1316
1476831/31/2024Actual1235
14768312/31/2023Actual1594
14768311/30/2023Actual1723
14768310/31/2023Actual1132
1476839/30/2023Actual1931
4836832/28/2024Actual1608
4836831/31/2024Actual1387
48368312/31/2023Actual1706
48368311/30/2023Actual1465
48368310/31/2023Actual1494
4836839/30/2023Actual1833
4836838/31/2023Actual1102
4836837/31/2023Actual1651

Hi,

This calculated column formula works

Column = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[fact[Property Id]]]=EARLIER(Data[fact[Property Id]]])&&Data[fact[Month]]]<=EARLIER(Data[fact[Month]]])&&Data[fact[Amount Type]]]=EARLIER(Data[fact[Amount Type]]])))

Hope this helps.

Ashish_Mathur_0-1708739106183.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

OK, then both formulas provided before (RANKX and RANK) work fine:

wini_R_0-1708725700057.png

 

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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