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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
tux117
Frequent Visitor

DAX calculating sales to new clients

Hi,

 

I'm trying to create a measure for calculating a sum of first-time sales. This is what my schema looks like.

 schema1.png

Currently I have this measure,

 

// Get the sum of sales quantity for the date equal to the first day of sales
[FirstSaleAmount] =
CALCULATE(SUM(Sales[SalesQty]; FILTER(Sales; MIN(Sales[Date]) = FIRSTNONBLANK(VALUES(Sales[Date]); 1)))

which works only when sales data is sliced by both client and product. Any idea how should I modify it to get a valid sum over all clients?

 

Thanks

 

1 ACCEPTED SOLUTION

Hi @tux117,

From whar I've read about SUMMARIZE it must be possible to incorporate it into a measure use it in a filter without creating a "physical" table, but I didn't manage to do that.

Yes, you don't need to create the physical summarize table in this scenario. Based on my test, you should be able to use the formula below to create the calculate column without the physical table. Smiley Happy

IsFirstSale =
CONTAINS (
    SUMMARIZE (
        Sales;
        Sales[Client];
        Sales[Product];
        "FirstSaleDate"; MIN ( Sales[Date] )
    );
    [Client]; Sales[Client];
    [Product]; Sales[Product];
    [FirstSaleDate]; Sales[Date]
)

 

Regards

View solution in original post

5 REPLIES 5
v-ljerr-msft
Employee
Employee

Hi @tux117,

 

Could you try the formula below to see if it works in your scenario? Smiley Happy

[FirstSaleAmount] =
SUMX (
    Client;
    SUMX (
        Product;
        CALCULATE (
            SUM ( Sales[SalesQty] );
            FILTER ( Sales; Sales[Date] = FIRSTNONBLANK ( VALUES ( Sales[Date] ); 1 ) )
        )
    )
)

 

Regards

Hmmm, it seems my reply has disappeared, so I'll have to write it once more.

 

@v-ljerr-msft unfortunately it does not work, the values in the table are right, when sliced by product and client, but overall result makes no sense.

 2017-08-10 17_15_45-123 - Power BI Desktop.png

I managed to do it the other way by creating a separate table containing dates of first sales

 

FirstTransactions = 
SUMMARIZE (
	Sales;
	Sales[Client];
	Sales[Product];
	"FirstSaleDate"; MIN ( Sales[Date] )
)

and then using it to create a custom column in the main table which shows if the record corresponds to the first sale,

 

IsFirstSale = 
CONTAINS(
	FirstTransactions; 
	FirstTransactions[Client]; Sales[Client]; 
	FirstTransactions[Product]; Sales[Product]; 
	FirstTransactions[FirstSaleDate]; Sales[Date]
)

The it's possible to use this column to filter

FirstSaleAmount2 = 
CALCULATE(
	SUM(Sales[SalesQty]); 
	Sales[IsFirstSale] = TRUE()
)

It looks pretty ugly but still works. From whar I've read about SUMMARIZE it must be possible to incorporate it into a measure use it in a filter without creating a "physical" table, but I didn't manage to do that.

Hi @tux117,

From whar I've read about SUMMARIZE it must be possible to incorporate it into a measure use it in a filter without creating a "physical" table, but I didn't manage to do that.

Yes, you don't need to create the physical summarize table in this scenario. Based on my test, you should be able to use the formula below to create the calculate column without the physical table. Smiley Happy

IsFirstSale =
CONTAINS (
    SUMMARIZE (
        Sales;
        Sales[Client];
        Sales[Product];
        "FirstSaleDate"; MIN ( Sales[Date] )
    );
    [Client]; Sales[Client];
    [Product]; Sales[Product];
    [FirstSaleDate]; Sales[Date]
)

 

Regards

@v-ljerr-msft cool, thank you! That does the job.

.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.