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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

auto increment column base on condition

Hi all,

 

I need to create a new column (Dax or PowerQuery) based on other column. This is my scenario

 

 

Country	date	Test	Indice
China	22/01/2020 0:00:00	548	2179
China	23/01/2020 0:00:00	643	2180
China	24/01/2020 0:00:00	920	2181
Spain	22/01/2020 0:00:00	0	9769
Spain	23/01/2020 0:00:00	0	9770
Spain	24/01/2020 0:00:00	0	9771
US	22/01/2020 0:00:00	1	11089
US	23/01/2020 0:00:00	1	11090
US	24/01/2020 0:00:00	2	11091

 

 

And this is what i would like to obatin:

 

 

Country	date	Test	Indice	WhatIWantIs
China	22/01/2020 0:00:00	548	2179	1
China	23/01/2020 0:00:00	643	2180	2
China	24/01/2020 0:00:00	920	2181	3
Spain	22/01/2020 0:00:00	0	9769	0
Spain	23/01/2020 0:00:00	0	9770	0
Spain	24/01/2020 0:00:00	1	9771	1
US	22/01/2020 0:00:00	1	11089	1
US	23/01/2020 0:00:00	1	11090	2
US	24/01/2020 0:00:00	2	11091	3

 

 

If column test is 0 , new column have to be 0 but if test is > 0 new column have to increment +1 also taking account the columns country and date to guarantee the integrity of data.

 

Thanks 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous 

Please try a new column like

 

What you want = COUNTX(FILTER(data,[Country]=EARLIER([Country]) && [date]<=EARLIER([date]) && [Test]>0),[date] )+0

 

 

File is attached after signature

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous 

Please try a new column like

 

What you want = COUNTX(FILTER(data,[Country]=EARLIER([Country]) && [date]<=EARLIER([date]) && [Test]>0),[date] )+0

 

 

File is attached after signature

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks , works perfect.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.