Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have a trending dataset where I'm trying to show which labels were added or removed by each month. Basically, I take a snapshot of an environment every month and store the data into a DB. Can someone write an example of a query that will show you distinct values when it compares one month to another? Here is an example of my data:
November:
December:
January:
Please write a query that shows me the unique labels for each month. Ideally states which ones were added and which ones were removed. Thanks!
Solved! Go to Solution.
Hi @you7777 ,
Thanks lbendlin for the quick answer and solution. I have some other ideas to add:
(1) This is my test data.
(2) We can create tables.
Table 2 =
var _min_date=MINX(ALL('Table'),[DB Loading Date])
var _table1= SELECTCOLUMNS('Table',[App Label],[DB Loading Date],[Status])
RETURN ADDCOLUMNS(FILTER('Table',[DB Loading Date] <> _min_date),"pre_date",EDATE([DB Loading Date],-1))
Table 3 =
var _table1= SELECTCOLUMNS('Table',[App Label],[Status],"Date",[DB Loading Date])
var _table2= SELECTCOLUMNS('Table 2',[App Label],[Status],"Date",[pre_date])
var _cancelled=ADDCOLUMNS( EXCEPT(_table1,_table2),"_status","cancelled","DB Loading Date",EDATE([Date],1))
var _add=ADDCOLUMNS(EXCEPT(_table2,_table1),"_status","add","DB Loading Date",EDATE([Date],1))
var _table3=SELECTCOLUMNS(_cancelled,[App Label],"Status",[_status],[DB Loading Date])
var _table4=SELECTCOLUMNS(_add,[App Label],"Status",[_status],[DB Loading Date])
var _table5= SELECTCOLUMNS(FILTER(UNION(_table3,_table4,'Table'),[Status]="active"),[App Label],[DB Loading Date])
var _table6= SELECTCOLUMNS(FILTER(UNION(_table3,_table4,'Table'),[Status]="add"),[App Label],[DB Loading Date])
var _table7= UNION(SELECTCOLUMNS(ADDCOLUMNS(EXCEPT(_table5,_table6),"Status","active"),[App Label],[status],[DB Loading Date]),_table4,_table3)
var _max_date=MAXX(_table7,[DB Loading Date])
RETURN
FILTER(_table7,[DB Loading Date]<>_max_date)
(3) Then the result is as follows. December saw a decrease of one compared to November, and January saw three new additions compared to December.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @you7777 ,
Thanks lbendlin for the quick answer and solution. I have some other ideas to add:
(1) This is my test data.
(2) We can create tables.
Table 2 =
var _min_date=MINX(ALL('Table'),[DB Loading Date])
var _table1= SELECTCOLUMNS('Table',[App Label],[DB Loading Date],[Status])
RETURN ADDCOLUMNS(FILTER('Table',[DB Loading Date] <> _min_date),"pre_date",EDATE([DB Loading Date],-1))
Table 3 =
var _table1= SELECTCOLUMNS('Table',[App Label],[Status],"Date",[DB Loading Date])
var _table2= SELECTCOLUMNS('Table 2',[App Label],[Status],"Date",[pre_date])
var _cancelled=ADDCOLUMNS( EXCEPT(_table1,_table2),"_status","cancelled","DB Loading Date",EDATE([Date],1))
var _add=ADDCOLUMNS(EXCEPT(_table2,_table1),"_status","add","DB Loading Date",EDATE([Date],1))
var _table3=SELECTCOLUMNS(_cancelled,[App Label],"Status",[_status],[DB Loading Date])
var _table4=SELECTCOLUMNS(_add,[App Label],"Status",[_status],[DB Loading Date])
var _table5= SELECTCOLUMNS(FILTER(UNION(_table3,_table4,'Table'),[Status]="active"),[App Label],[DB Loading Date])
var _table6= SELECTCOLUMNS(FILTER(UNION(_table3,_table4,'Table'),[Status]="add"),[App Label],[DB Loading Date])
var _table7= UNION(SELECTCOLUMNS(ADDCOLUMNS(EXCEPT(_table5,_table6),"Status","active"),[App Label],[status],[DB Loading Date]),_table4,_table3)
var _max_date=MAXX(_table7,[DB Loading Date])
RETURN
FILTER(_table7,[DB Loading Date]<>_max_date)
(3) Then the result is as follows. December saw a decrease of one compared to November, and January saw three new additions compared to December.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You can study the approach here : https://www.daxpatterns.com/new-and-returning-customers/
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
13 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
20 | |
14 | |
11 | |
10 | |
10 |