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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
gbarr12345
Post Patron
Post Patron

Calculated Table showing 2 products sold within 90 days

Hi everyone, 

 

I have created a calculated table that shows who bought the product called "21NZ1020" within the last 6 months excluding the Customer class called STAFF . This calculated table works for me.

 

I'm now looking to add another product into the code so I want it to show both 23NZ1020 and also 23NZ4170.

 

Is it possible to show me how to do this?

 

My working code is below. Many Thanks in advance!

 

NZ1060 in 2024 =
VAR _StartDateBetween =
    DATE( 2024, 01, 01)
VAR _EndDateBetween =
    DATE( 2024 , 05, 31)
VAR _IncludedItemProducts = { "23NZ1020"}
VAR _ExcludeStaff =
    SELECTCOLUMNS(
        FILTER(
            'Dimension Customer' ,
            'Dimension Customer'[customer class] IN { "STAFF" }
        ) ,
 
        "Customer ID class staff" , 'Dimension Customer'[customer]
    )
 
VAR _IncludedChainField =
    SELECTCOLUMNS(
        FILTER(
            'Dimension Customer' ,
            'Dimension Customer'[chain] IN { "FSNI" }
        ) ,
 
        "Customer ID class staff" , 'Dimension Customer'[customer]
    )
 
VAR Result =
    CALCULATETABLE(
        'Module Sales with Inventory' ,
        FILTER(
            ALL( CalendarTable[Date] ) ,
            CalendarTable[Date] > _StartDateBetween
            && CalendarTable[Date] <= _EndDateBetween
        ) ,
 
        FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[item] = _IncludedItemProducts ) ,
        FILTER( 'Module Sales with Inventory' , NOT ('Module Sales with Inventory'[customer] ) IN _ExcludeStaff ) ,
        FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[customer] IN _IncludedChainField )
    )
 
    RETURN
        Result
1 ACCEPTED SOLUTION
some_bih
Super User
Super User

Hi @gbarr12345 try v3

NZ1060 in 2024 v3 =
VAR _StartDateBetween =
DATE( 2024, 01, 01)
VAR _EndDateBetween =
DATE( 2024 , 05, 31)
VAR _IncludedItemProducts = { "23NZ1020","23NZ4170"}
VAR _ExcludeStaff =
SELECTCOLUMNS(
FILTER(
'Dimension Customer' ,
'Dimension Customer'[customer class] IN { "STAFF" }
) ,

"Customer ID class staff" , 'Dimension Customer'[customer]
)

VAR _IncludedChainField =
SELECTCOLUMNS(
FILTER(
'Dimension Customer' ,
'Dimension Customer'[chain] IN { "FSNI" }
) ,

"Customer ID class staff" , 'Dimension Customer'[customer]
)

VAR Result =
CALCULATETABLE(
'Module Sales with Inventory' ,
FILTER(
ALL( CalendarTable[Date] ) ,
CalendarTable[Date] > _StartDateBetween
&& CalendarTable[Date] <= _EndDateBetween
) ,

FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[item] IN { "23NZ1020","23NZ4170"} ) ,
FILTER( 'Module Sales with Inventory' , NOT ('Module Sales with Inventory'[customer] ) IN _ExcludeStaff ) ,
FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[customer] IN _IncludedChainField )
)

RETURN
Result





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






View solution in original post

4 REPLIES 4
some_bih
Super User
Super User

Hi @gbarr12345 try v3

NZ1060 in 2024 v3 =
VAR _StartDateBetween =
DATE( 2024, 01, 01)
VAR _EndDateBetween =
DATE( 2024 , 05, 31)
VAR _IncludedItemProducts = { "23NZ1020","23NZ4170"}
VAR _ExcludeStaff =
SELECTCOLUMNS(
FILTER(
'Dimension Customer' ,
'Dimension Customer'[customer class] IN { "STAFF" }
) ,

"Customer ID class staff" , 'Dimension Customer'[customer]
)

VAR _IncludedChainField =
SELECTCOLUMNS(
FILTER(
'Dimension Customer' ,
'Dimension Customer'[chain] IN { "FSNI" }
) ,

"Customer ID class staff" , 'Dimension Customer'[customer]
)

VAR Result =
CALCULATETABLE(
'Module Sales with Inventory' ,
FILTER(
ALL( CalendarTable[Date] ) ,
CalendarTable[Date] > _StartDateBetween
&& CalendarTable[Date] <= _EndDateBetween
) ,

FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[item] IN { "23NZ1020","23NZ4170"} ) ,
FILTER( 'Module Sales with Inventory' , NOT ('Module Sales with Inventory'[customer] ) IN _ExcludeStaff ) ,
FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[customer] IN _IncludedChainField )
)

RETURN
Result





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






That works, thank you so much!

some_bih
Super User
Super User

Hi @gbarr12345 try version 2 below

NZ1060 in 2024 v2 =
VAR _StartDateBetween =
DATE( 2024, 01, 01)
VAR _EndDateBetween =
DATE( 2024 , 05, 31)
VAR _IncludedItemProducts = { "23NZ1020"}
VAR _IncludedItemProducts_2 = { "23NZ4170"}
VAR _ExcludeStaff =
SELECTCOLUMNS(
FILTER(
'Dimension Customer' ,
'Dimension Customer'[customer class] IN { "STAFF" }
) ,

"Customer ID class staff" , 'Dimension Customer'[customer]
)

VAR _IncludedChainField =
SELECTCOLUMNS(
FILTER(
'Dimension Customer' ,
'Dimension Customer'[chain] IN { "FSNI" }
) ,

"Customer ID class staff" , 'Dimension Customer'[customer]
)

VAR Result =
CALCULATETABLE(
'Module Sales with Inventory' ,
FILTER(
ALL( CalendarTable[Date] ) ,
CalendarTable[Date] > _StartDateBetween
&& CalendarTable[Date] <= _EndDateBetween
) ,

FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[item] = _IncludedItemProducts || 'Module Sales with Inventory'[item] = _IncludedItemProducts_2 ) ,
FILTER( 'Module Sales with Inventory' , NOT ('Module Sales with Inventory'[customer] ) IN _ExcludeStaff ) ,
FILTER( 'Module Sales with Inventory' , 'Module Sales with Inventory'[customer] IN _IncludedChainField )
)

RETURN
Result





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi there,

 

Thanks for your response.

 

I tried your code and am getting the following error.

 

Any idea where I'm going wrong?

 

gbarr12345_0-1716931257619.png

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Find out what's new and trending in the Fabric Community.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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