Search code examples
powerbidaxmeasure

Calculate count of users which use the discount in their first order


How can I calculate the count of users which use discounts in their first order, in Power BI?

for example, in this data, the results should be 2 users or 50% of users:

pic1


Solution

  • We can do that this way. First, calculate min purchase date for user_id then check if discount is greater than 0:

    FirstOrderWithDiscount = 
    
    var _tempTab = TREATAS(
        CALCULATETABLE(ADDCOLUMNS(VALUES(DiscountTab[user_id]),"minPurch", calculate(min('DiscountTab'[purchase_date]), ALLEXCEPT(DiscountTab, 'DiscountTab'[user_id]))), DiscountTab[discount] > 0)
        , DiscountTab[user_id], DiscountTab[purchase_date])
    
    return
    CALCULATE( countrows(DiscountTab), _tempTab,  DiscountTab[discount] > 0)
    

    enter image description here