Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi,
I want to create a measure that sums sales figures based on customers who bought something this edition, but not last.
The edition is just a book edition and not relevant to a time/date. I would write the following in SQL:
SELECT
SUM(a.Total) AS TotalSales
FROM SalesTable a
WHERE a.edition = "2017"
AND a.accountid NOT IN (SELECT accountid FROM SalesTable WHERE a.edition = "2016")
Any idea if this is posibble to do in a Measure?
You may take a good look at the article below.
https://www.sqlbi.com/articles/from-sql-to-dax-in-and-exists/
Hi @wenners68,
Try this code:
_2017 =
VAR _2016 = SELECTCOLUMNS(FILTER(SalesTable; SalesTable[EDITION] = 2016); "ACCOUNTID"; SalesTable[ACCOUNT_ID])
VAR _2017 = SELECTCOLUMNS(FILTER(SalesTable; SalesTable[EDITION] = 2017); "ACCOUNTID"; SalesTable[ACCOUNT_ID])
VAR _tbl = EXCEPT(_2017; _2016)
RETURN
SUMX(FILTER(SalesTable; SalesTable[ACCOUNT_ID] IN (_tbl)); SalesTable[TOTAL])
Hi,
thanks, but that will only give you a total for the entire edition.
Perhaps create a calculated column first that goes something like:
BoughtLastYear = IF(ISBLANK(SUMX(FILTER(TotalSales,TotalSales[accountid]=EARLIER(TotalSales[accountid])&&TotalSales[edition]=EARLIER(TotalSales[edition]-1)),TotalSales[Total)),"No","Yes")
Should create a column with Yes if they bought last year and No if they didn't. Then you could create a Measure like:
MyMeasure = CALCULATE(SUM(TotalSales[Total]),FILTER(TotalSales,BoughtLastYear="Yes"))
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 35 | |
| 31 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 75 | |
| 72 | |
| 39 | |
| 35 | |
| 23 |