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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
jobf
Helper II
Helper II

Create a column to sort dates

Please see the table below:

Field  Date
P1  01/01/2025
P1  02/25/2025
P1  01/22/2025
P2  01/10/2025
P2  03/02/2025
P2  02/15/2025
P2  01/30/2025


This table shows the dates that a certain product was applied to a certain field. I need a column that shows the application number that occurred on that date. It should look like this:

Field  Date  Application
P1  01/01/2025  1
P1  02/25/2025  3
P1  01/22/2025  2
P2  01/10/2025  1
P2  03/02/2025  4
P2  02/15/2025  3
P2  01/30/2025  2
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for ryan_mayu, wini_R and parry2k's concern about this issue.

 

Hi, @jobf 

You can try the wini_R and ryan_mayu methods and also I will share another method which I hope will help you:


You can create a calculated column based on the following DAX formula:

Application = 
VAR CurrentField = 'Table'[Field]
VAR CurrentDate = 'Table'[Date]
RETURN
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        'Table',
        'Table'[Field] = CurrentField &&
        'Table'[Date] <= CurrentDate
    )
)

 

vfenlingmsft_0-1739328150252.png

 

I have attached the pbix file for this example below, hope it helps you.

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thanks for ryan_mayu, wini_R and parry2k's concern about this issue.

 

Hi, @jobf 

You can try the wini_R and ryan_mayu methods and also I will share another method which I hope will help you:


You can create a calculated column based on the following DAX formula:

Application = 
VAR CurrentField = 'Table'[Field]
VAR CurrentDate = 'Table'[Date]
RETURN
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        'Table',
        'Table'[Field] = CurrentField &&
        'Table'[Date] <= CurrentDate
    )
)

 

vfenlingmsft_0-1739328150252.png

 

I have attached the pbix file for this example below, hope it helps you.

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ryan_mayu
Super User
Super User

@jobf 

 

you can try to create a column in PQ

 

= Table.AddColumn(#"Changed Type", "Custom", each Table.RowCount(Table.SelectRows(#"Changed Type",(x)=>x[Field]=[Field] and x[Date]<=[Date])))

 

or you can try to use DAX to create a column

 

Column = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Field]=EARLIER('Table'[Field])&&'Table'[Date]<=EARLIER('Table'[Date])))
 
11.PNG
 
pls see the attachment below




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

Proud to be a Super User!




wini_R
Solution Supplier
Solution Supplier

Hey @jobf,

If by chance you would like to add a column in Power Query,  then you can try the method below. Please paste the code in Advanced editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjBU0lFSUDAw1AciIwMjU6VYHYSokb6RKaYoUKERkqgRTNTQAFPUWN8Ai1ojfUNTbCYYw0yIBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Field = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Field"}, {{"all", each Table.AddIndexColumn(Table.Sort(_, {{"Date", Order.Ascending}}), "Application", 1, 1 )}}),
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Date", "Application"}, {"Date", "Application"})
in
    #"Expanded all"

Output table:

wini_R_0-1739303114209.png

 

parry2k
Super User
Super User

@jobf you can use RANK or ROWNUMBER function to calculate it. There are many blogs/videos on it. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.