Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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...
  • barritown's avatar
    3 years ago

    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. 

    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