cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
SankeyThakkar_7
Helper II
Helper II

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 @SankeyThakkar_7,

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 @SankeyThakkar_7,

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors