Unit Fiscal Week Sales Calculated Table and Query

Unit Fiscal Week Sales = 

 FILTER(

ADDCOLUMNS(

SUMMARIZE(

'Financial Summary',

'Unit'[UnitId],

'Calendar'[Fiscal Week End Date]

),

"Weekly Sales", [Sales]

),

[Weekly Sales] > 0

)


-- query to determine the Units that have sales > $0 in every week of the report date range

DEFINE
    VAR Units =
        CALCULATETABLE(
            VALUES(Unit[UnitId]),
            Unit[Market] = "Domestic",    -- report filter
            Unit[Brand] = "Carl's Jr."    -- page filter: "Carl's Jr." or "Hardee's"
        )
    VAR ReportDateRange =                 -- provided by Slicer
        { 
            DATE(2021, 2, 1),
            DATE(2021, 2, 8)
            DATE(2021, 2, 15)
            DATE(2021, 2, 22) 
            
            /*
            DATE(2021, 4, 12), 
            DATE(2021, 4, 19), 
            DATE(2021, 4, 26), 
            DATE(2021, 5, 3) 
            */
        }
    VAR UnitWeeklySales =                 -- get units and sales by week; no $0 sales in calculated table
        CALCULATETABLE(
            'Unit Fiscal Week Sales',
            'Unit Fiscal Week Sales'[Fiscal Week End Date] IN ReportDateRange
        )
    VAR UnitWeeklySalesCount =
        GROUPBY(
            UnitWeeklySales,
            'Unit Fiscal Week Sales'[UnitId],
            "@WeeksWithSales", SUMX(CURRENTGROUP(), 1)
        )
    VAR UnitIdFilter = 
        FILTER(
            UnitWeeklySalesCount,
            [@WeeksWithSales] = COUNTROWS(ReportDateRange)
        )
EVALUATE

    --UnitWeeklySales

    INTERSECT(
        Units,
        TREATAS(
            SELECTCOLUMNS(
                UnitIdFilter, 
                "UnitId"
                [UnitId]
            ),
            'Unit'[UnitId]
        )
    )

Comments

Popular posts from this blog

Difference between DISTINCT and VALUES in DAX