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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Taufik_8774
Regular Visitor

How to convert countifs from XL to power query

Dear sir,

kindly help convert "COUNTIFS" from excel to power BI,

Sample for below data

I use formula on column Sequence, cell C2=COUNTIFS($A$1:$A2;$A2;$B$1:$B2;$B2) then I drag-down to all collumn below.

if serial No and StageName is same, then sequence will count 1, 2, etc...

Taufik_8774_0-1710224695937.png

 

3 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Taufik_8774 

 

Please try this:

First of all, I create a set of sample:

vzhengdxumsft_0-1710730464493.png

Then Transform Data > Add column > Index column

vzhengdxumsft_2-1710730771336.png

Then create a calculate column:

Sequence =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[SerualNo] = EARLIER ( 'Table'[SerualNo] )
            && 'Table'[StageName] = EARLIER ( 'Table'[StageName] )
            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    )
)

The result is as follow:

vzhengdxumsft_3-1710730877100.png

Best Regards

Zhengdong Xu
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

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"SerialNo", "StageName"}, {{"Sequence", each Table.AddIndexColumn(_,"Seq",1,1)}}),
    #"Expanded Sequence" = Table.ExpandTableColumn(#"Grouped Rows", "Sequence", {"Seq"}, {"Seq"})
in
    #"Expanded Sequence"

Hope this helps.

Ashish_Mathur_0-1710732975585.png

 


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

View solution in original post

Thank You so much, this formula really work properly. Thanks sir  v-zhengdxu-msft 

View solution in original post

5 REPLIES 5
Taufik_8774
Regular Visitor

Sorry sir, this difficult to understand by me.

I'm new in power BI

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"SerialNo", "StageName"}, {{"Sequence", each Table.AddIndexColumn(_,"Seq",1,1)}}),
    #"Expanded Sequence" = Table.ExpandTableColumn(#"Grouped Rows", "Sequence", {"Seq"}, {"Seq"})
in
    #"Expanded Sequence"

Hope this helps.

Ashish_Mathur_0-1710732975585.png

 


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

Hi @Taufik_8774 

 

Please try this:

First of all, I create a set of sample:

vzhengdxumsft_0-1710730464493.png

Then Transform Data > Add column > Index column

vzhengdxumsft_2-1710730771336.png

Then create a calculate column:

Sequence =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[SerualNo] = EARLIER ( 'Table'[SerualNo] )
            && 'Table'[StageName] = EARLIER ( 'Table'[StageName] )
            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    )
)

The result is as follow:

vzhengdxumsft_3-1710730877100.png

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank You so much, this formula really work properly. Thanks sir  v-zhengdxu-msft 

tharunkumarRTK
Super User
Super User

@Taufik_8774 

Please find my solution 

let
    Source = Table.FromColumns({{"1A2103XN000251","1A2109XN001414","1A2109XN001414","1A2404PP034406","1A2404PP034406","1A2404PP034406","1A2404PP034406","1A2404PP040883","1A2404PP040883","1A2404PP040883"},{"Imager Alignment 1","Imager Alignment 1","Imager Alignment 1","Functional 2","Functional 2","Calibration 3","Calibration 3","Imager Alignment 1","Functional 2","Calibration 3"}}, {"SerialNo","StageName"}),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each _),
    CountIfs = Table.FromColumns(List.Accumulate( #"Added Custom"[Custom], {{},{}}, (s,c)=> { s{0} & { [ SerialNo=c[SerialNo], StageName = c[StageName]  ]},  s{1} & { 
List.Sum(List.Accumulate(s{0}, {0}, (s1,c1)=> if c1[SerialNo] = c[SerialNo] and c1[StageName] = c[StageName] then s1 & {1} else s1 & {0}    ))  + 1
 } } ), {"Data", "Count"}),
    #"Expanded Data" = Table.ExpandRecordColumn(CountIfs, "Data", {"SerialNo", "StageName"}, {"SerialNo", "StageName"})
in
    #"Expanded Data"

 

 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors