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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
haichenhuang
Frequent Visitor

Values based on number of reoccurence in another column

Hi there. I need to create another column "Value" from data in collumn "Year":

 

haichenhuang_0-1667619343835.png

 

What it needs to do is count the number of times the Year value is duplicated, and list down which number of occurence it is. The data in "Values" in the screenshot above is manual entry and I need a way of powerBI doing this automatically. Thanks.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @haichenhuang ,

Besides that the method as suggested by @Ashish_Mathur , you can achieve it by DAX. If there is one date field (as shown below) or index field that uniquely identify each record in your table , create the following calculated column to get the value. You can find the details in the attachment.

Value = 
CALCULATE (
    COUNT ( 'Table'[Date] ),
    FILTER (
        'Table',
        'Table'[Year] = EARLIER ( 'Table'[Year] )
            && 'Table'[Date] <= EARLIER ( 'Table'[Date] )
    )
)

yingyinr_2-1667806297354.png

Otherwise, you need to add an index column in Power Query Editor first. If so, the method from @Ashish_Mathur  is better....

yingyinr_0-1667805263003.png

 #"Added Index" = Table.AddIndexColumn(#"Change Type", "Index", 1, 1, Int64.Type)

yingyinr_1-1667806068993.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @haichenhuang ,

Besides that the method as suggested by @Ashish_Mathur , you can achieve it by DAX. If there is one date field (as shown below) or index field that uniquely identify each record in your table , create the following calculated column to get the value. You can find the details in the attachment.

Value = 
CALCULATE (
    COUNT ( 'Table'[Date] ),
    FILTER (
        'Table',
        'Table'[Year] = EARLIER ( 'Table'[Year] )
            && 'Table'[Date] <= EARLIER ( 'Table'[Date] )
    )
)

yingyinr_2-1667806297354.png

Otherwise, you need to add an index column in Power Query Editor first. If so, the method from @Ashish_Mathur  is better....

yingyinr_0-1667805263003.png

 #"Added Index" = Table.AddIndexColumn(#"Change Type", "Index", 1, 1, Int64.Type)

yingyinr_1-1667806068993.png

Best Regards

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Partition = Table.Group(Source, {"Year"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Index"}, {"Index"})
in
    #"Expanded Partition"

Hope this helps.

Untitled.png


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

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.