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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
komald
Helper I
Helper I

How to get items added and removed on selection of month

Hello,

I have following data.

komald_0-1676440769933.png



On the basis of data i have create a visual which shows products added and removed by month.
if i select month feb , then it should show me comparison for last and current month i.e jan and feb month.

if product is present in last month but absent in current month then product status should be "removed"

if product is absent in last month but present in current month then product status should be "added"

if product is present in both last and current month then status should be "Remain"

 

month slicer


product_id for previous month | product_id for current month  | status


Thanks in advance


1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @komald 

 

You can try the following methods.

New Table:

Date = CALENDAR(DATE(2022,1,1),DATE(2022,4,30))
Month = MONTH([Date])

Measure:

Status = 
Var _Previousmonth = SELECTEDVALUE('Date'[Month])-1
Var _table=CALCULATETABLE(VALUES('Table'[Product ID]),FILTER(ALL('Table'),[Month]=_Previousmonth))
Var _N1=IF(SELECTEDVALUE('Table'[Product ID]) in _table,1,0)
Return
SWITCH(TRUE(),
_N1=0&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month]),"Added",
_N1=1&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month]),"Remain")
Previous month = IF(SELECTEDVALUE('Table'[Month])=SELECTEDVALUE('Date'[Month])-1,1,0)
Previous month status = 
Var _table=CALCULATETABLE(VALUES('Table'[Product ID]),FILTER(ALL('Table'),[Month]=SELECTEDVALUE('Table'[Month])+1))
Var _N1=IF(SELECTEDVALUE('Table'[Product ID]) in _table,1,0)
Return
SWITCH(TRUE(),
_N1=0&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month])+1,"Removed",
_N1=1&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month])+1,"Remain")

vzhangti_0-1676962798707.pngvzhangti_1-1676962811634.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-zhangti
Community Support
Community Support

Hi, @komald 

 

You can try the following methods.

New Table:

Date = CALENDAR(DATE(2022,1,1),DATE(2022,4,30))
Month = MONTH([Date])

Measure:

Status = 
Var _Previousmonth = SELECTEDVALUE('Date'[Month])-1
Var _table=CALCULATETABLE(VALUES('Table'[Product ID]),FILTER(ALL('Table'),[Month]=_Previousmonth))
Var _N1=IF(SELECTEDVALUE('Table'[Product ID]) in _table,1,0)
Return
SWITCH(TRUE(),
_N1=0&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month]),"Added",
_N1=1&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month]),"Remain")
Previous month = IF(SELECTEDVALUE('Table'[Month])=SELECTEDVALUE('Date'[Month])-1,1,0)
Previous month status = 
Var _table=CALCULATETABLE(VALUES('Table'[Product ID]),FILTER(ALL('Table'),[Month]=SELECTEDVALUE('Table'[Month])+1))
Var _N1=IF(SELECTEDVALUE('Table'[Product ID]) in _table,1,0)
Return
SWITCH(TRUE(),
_N1=0&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month])+1,"Removed",
_N1=1&&SELECTEDVALUE('Date'[Month])=SELECTEDVALUE('Table'[Month])+1,"Remain")

vzhangti_0-1676962798707.pngvzhangti_1-1676962811634.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.