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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Help in dax

I have two tables in Power BI: "Ownership" and "Sales". The "Ownership" table contains the product-wise ownership percentages by owner, while the "Sales" table contains information about the sales, including the date and product. The ownership percentages vary each quarter, and I need to calculate the share by owner based on these changing percentages.
       
Table: Ownership     
       
productownerfyfqpercentage  
xdattufy24q150  
xdattufy24q270  
xsanketfy24q150  
xsanketfy24q230  
ydattufy24q130  
ydattufy24q270  
ysanketfy24q170  
ysanketfy24q230  
       
       
       
Table: Sales      
       
dateproductsales    
03-04-2023x10    
04-04-2023y20    
05-04-2023x30    
06-04-2023y40    
07-04-2023x50    
08-04-2023y60    
09-04-2023x70    
10-04-2023y80    
03-05-2023x90    
04-05-2023y100    
05-05-2023x110    
06-05-2023y120    
07-05-2023x130    
05-07-2023y140    
06-07-2023x150    
07-07-2023y160    
08-07-2023x170    
09-07-2023y180    
10-07-2023x190    
11-07-2023y200    
12-07-2023x210    
13-07-2023y220    
       
       
       
Our financial cycle starts on April 1st and ends on March 31st. Each financial quarter consists of three months. For example, financial Q1 includes April, May, and June.
       
I would like to create a report with a date filter so that when the user selects a date range, the sales data is filtered accordingly. For example, if the user selects the date range from 10/4/23 to 9/7/23, the sales data should be filtered as shown below:
       
Table: Filtered Sales     
       
dateproductsales    
10-04-2023y80    
03-05-2023x90    
04-05-2023y100    
05-05-2023x110    
06-05-2023y120    
07-05-2023x130    
05-07-2023y140    
06-07-2023x150    
07-07-2023y160    
08-07-2023x170    
09-07-2023y180    
       
       
       
       
       
Based on the ownership percentages and filtered sales data, I would like to create a final report as a table visual in Power BI.
       
Table: Final Report     
       
OwnerTotal     
sanket615     
dattu815     
       
       
       
       
       
The calculation for the final report can be understood from the table below:
       
Table: Calculation Details    
       
       
       
ownerfyfqproductperctotal(ignore owner)share
dattufy24q1x50330165
sanketfy24q1x50330165
dattufy24q1y3030090
sanketfy24q1y70300210
dattufy24q2x70320224
sanketfy24q2x3032096
dattufy24q2y70480336
sanketfy24q2y30480144
       
       
       
       
       
In the "Calculation Details" table, I have computed the share by owner based on the ownership percentages and total sales (ignoring the owner). For each owner, financial year (FY), financial quarter (FQ), and product combination, I calculated the share using the following formula:
       
Share = Total (Ignore Owner) * Percentage   
       
       
1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @Anonymous,

I could propose to solve your problem with the measure below. If you have a calendar table, you can simplify the part where "qtr" and "fy" are calculated. Your test case is OK as you can see on the screenshot. 

barritown_0-1688730524497.png

In plain text for convenience:

Measure = 
VAR Tbl = 
ADDCOLUMNS ( 
    ADDCOLUMNS (
        CROSSJOIN (
            VALUES ( Ownership[owner] ),
            SUMMARIZE (
                ADDCOLUMNS ( Sales, 
                    "qtr", 
                    VAR _temp = QUARTER ( [date] ) 
                    RETURN "q" & CONVERT ( IF ( _temp = 1, 4, _temp - 1 ), STRING ),
                    "fy",
                    VAR y = YEAR ( [date] )
                    VAR res = IF ( MONTH ( [date] ) IN { 1, 2, 3 }, y, y + 1 )
                    RETURN "fy" & RIGHT ( CONVERT ( res, STRING ), 2 ) ),
            [fy], [qtr], [product], 
            "total sales",
            SUM (Sales[sales]) ) ),
        "productperc",
        VAR CurrentOwner = [owner]
        VAR CurrentQtr = [qtr]
        VAR CurrentProduct = [product]
        VAR CurrentFY = [fy]
        RETURN MINX ( FILTER ( Ownership, [owner] = CurrentOwner && [fq] = CurrentQtr && [product] = CurrentProduct && [fy] = CurrentFY ), [percentage] ) ),
    "share",
    [total sales] * [productperc] / 100 )
RETURN SUMX ( Tbl, [share] )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

1 REPLY 1
barritown
Super User
Super User

Hi @Anonymous,

I could propose to solve your problem with the measure below. If you have a calendar table, you can simplify the part where "qtr" and "fy" are calculated. Your test case is OK as you can see on the screenshot. 

barritown_0-1688730524497.png

In plain text for convenience:

Measure = 
VAR Tbl = 
ADDCOLUMNS ( 
    ADDCOLUMNS (
        CROSSJOIN (
            VALUES ( Ownership[owner] ),
            SUMMARIZE (
                ADDCOLUMNS ( Sales, 
                    "qtr", 
                    VAR _temp = QUARTER ( [date] ) 
                    RETURN "q" & CONVERT ( IF ( _temp = 1, 4, _temp - 1 ), STRING ),
                    "fy",
                    VAR y = YEAR ( [date] )
                    VAR res = IF ( MONTH ( [date] ) IN { 1, 2, 3 }, y, y + 1 )
                    RETURN "fy" & RIGHT ( CONVERT ( res, STRING ), 2 ) ),
            [fy], [qtr], [product], 
            "total sales",
            SUM (Sales[sales]) ) ),
        "productperc",
        VAR CurrentOwner = [owner]
        VAR CurrentQtr = [qtr]
        VAR CurrentProduct = [product]
        VAR CurrentFY = [fy]
        RETURN MINX ( FILTER ( Ownership, [owner] = CurrentOwner && [fq] = CurrentQtr && [product] = CurrentProduct && [fy] = CurrentFY ), [percentage] ) ),
    "share",
    [total sales] * [productperc] / 100 )
RETURN SUMX ( Tbl, [share] )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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