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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ed_mcdill
Advocate II
Advocate II

Sum of Sales for Customers who bought in 2 specific years

Hi

 

I have a Sales fact table, with Customer and Dates dim tables.

 

I would like to return the sum of sales for customers, Sales[Total Sales], for customers Customer[Name], who made a purchase in both Dates[CY]="CY17" && Dates[CY]="CY18"

 

I seem unable to create a filter for two CY's, any pointers?

7 REPLIES 7
fhill
Resident Rockstar
Resident Rockstar

There is probably a more programtic way of doing this, but this is one solution:

 

1. Filter you Date Column for 1/1/2016 and After.  Duplicate your Date Column in Query Editor and Split the new column to only extract the Year (choose your delimter and Left/Right most depending on your date format)  You now have a new column of Year. 

2.  Duplicate your Table (Query) and delete everthing but CustomerID and Year from the new Table (Query).  Select both Columns and 'Remove Duplciate Rows'.  Now you only have a list of customers and each year they placed an order.

3. Use the' Group By' feature on the 'Transform' tab.  Group by CustomerID and "Count Distint Rows" under Operation.  You now have 1 line per customer with how many DISTINCT Years they placed orders.

4. Close and Apply Query Editor and Manage Relationships to link your Customers from the new Table (Query) to the original Table (Query).

5. Create your visual and apply a filter for the Discinct Years Count Column you created in Step 3.  Set you filter to 2.

 

Here's a sample table I created and the end result following these steps:

Capture.PNGSample below.




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Thanks for the reply. I must admit I've been trying to find a solution through a measure as I access this through a SSAS TM so don't have the ability to make changes to the data sources.

Hi @ed_mcdill,

You can a calculated column in Fact table using the formula: CY=RELATED(Dates[CY])

Then create a new table to get the sale records by clicking "New Table" under Modeling on Home page, type the formula.

FilteredTable=INTERSECT(FILTER(FactTable, FactTable[CY]="CY18"),FILTER(FactTable, FactTable[CY]="CY18"))


Then calculated what you want using the similar formula.

sum=CALCULATE(SUM(FilteredTable[Sales]),ALL(FilteredTable))


Best Regards,
Angelia

Many thanks, maybe I'll contact our db team to see if they will put this in for me.

Hi @ed_mcdill,

Got it, please mark the helpful reply as answer, or share your own solution, so that more people will benefit from here.

Best Regards,
Angelia

Thanks, I'm still trying to solve this using a calculated measure and will be sure to post here once I do.

Hi @ed_mcdill,

Got it.

Best Regards,
Angelia

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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