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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Not applicable

Count purchases after another purchase

Hello everybody,


I've got a table like:

id | timestamp | uid | tariff_name |

1    16.01.2017   id001  tariff_A

2    16.01.2017   id002  tariff_A

3    17.01.2017   id001  tariff_B

4    18.01.2017   id002  tariff_C

5    18.01.2017   id003  tariff_A


How can i count: all purchases for id001 made after purchasing tariff_A ? (1 purchase for example table)

                            sum of id that purchase smth after purchasing tariff_A? (2 (id001 & id002 id for example table)

Resolver IV
Resolver IV

hi @Anonymous

you could do a calc column like this

CntLaterPurchases = 
      AND( table[uid] = EARLIER(table[UID]), table[id] > EARLIER(table[id]) )



Not applicable

hi @BetterCallFrank thanks for reply, i've got the following error: "EARLIER/EARLIEST refers to an earlier row context which doesn't exist", what can i do wrong?)

And what about if the first purchase was tariff_B, then tariff_A, and then tariff_C - i need to count only tariff_C - is it possible with your suggestion?

Hi @Anonymous


for your first question, try this measure:

Cnt Later Purchase of Customer:=
IF( HASONEVALUE(Table1[uid] ), VAR TheUID = VALUES( Table1[uid] ) VAR TheID = MAX( Table1[id] ) RETURN COUNTROWS( FILTER( ALL( Table1 ), AND( Table1[uid] = TheUID, Table1[id] > TheID ) ) ) )

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.