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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
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)

3 REPLIES 3
BetterCallFrank
Resolver IV
Resolver IV

hi @Anonymous

you could do a calc column like this

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

HTH,

Frank

Anonymous
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

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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