Categories: DAX
Tags:

Here are solutions for the DAX Questions for Solar Panel Sales Dataset (2024-2025)

DAX Formulas for Solar Panel Sales Dataset


1. YTD Sales Calculation (Wattage)

🧠 Goal: Total Wattage Sold Year-to-Date

Wattage YTD = 
TOTALYTD(
    SUM('Sales'[Wattage (W)]),
    'Sales'[Sale Date]
)

2. Difference in Sales vs Previous Month

🧠 Goal: Month-over-Month Wattage Change

Wattage MoM Change = 
VAR CurrentMonth = 
    CALCULATE(SUM('Sales'[Wattage (W)]))
VAR PreviousMonth = 
    CALCULATE(
        SUM('Sales'[Wattage (W)]),
        DATEADD('Sales'[Sale Date], -1, MONTH)
    )
RETURN
CurrentMonth - PreviousMonth

3. First Sale Date per Panel Type

🧠 Goal: Earliest sale date for each panel type

First Sale Date = 
CALCULATE(
    FIRSTDATE('Sales'[Sale Date]),
    ALLEXCEPT('Sales', 'Sales'[Panel Type])
)

4. % Contribution of Segment (2025)

🧠 Goal: Segment’s share of total wattage in 2025

% Segment Contribution 2025 = 
DIVIDE(
    CALCULATE(SUM('Sales'[Wattage (W)]), YEAR('Sales'[Sale Date]) = 2025),
    CALCULATE(SUM('Sales'[Wattage (W)]), ALL('Sales'), YEAR('Sales'[Sale Date]) = 2025)
)

5. Rank of Panel Efficiency

🧠 Goal: Rank panels by efficiency

Panel Efficiency Rank = 
RANKX(
    ALL('Sales'),
    CALCULATE(AVERAGE('Sales'[Efficiency (%)])),
    ,
    DESC
)

6. Cumulative Wattage

🧠 Goal: Running total of wattage sold

Cumulative Wattage = 
CALCULATE(
    SUM('Sales'[Wattage (W)]),
    FILTER(
        ALLSELECTED('Sales'[Sale Date]),
        'Sales'[Sale Date] <= MAX('Sales'[Sale Date])
    )
)

7. Dynamic Report Title Based on Year Selection

🧠 Goal: Dynamic Title like “Sales Summary for the Year 2024”

Dynamic Title = 
"Sales Summary for the Year " & SELECTEDVALUE(YEAR('Sales'[Sale Date]), "All Years")

8. Season Label (Summer or Winter)

🧠 Goal: Add a calculated column for season

Season = 
SWITCH(
    TRUE(),
    MONTH('Sales'[Sale Date]) IN {4, 5, 6, 7, 8, 9}, "Summer",
    "Winter"
)

9. Distinct Panel Configurations Count

🧠 Goal: Unique combinations of Panel Type and Wattage

Distinct Panel Configurations = 
CALCULATE(
    COUNTROWS(
        SUMMARIZE('Sales', 'Sales'[Panel Type], 'Sales'[Wattage (W)])
    )
)

10. Latest Sale Date by Segment

🧠 Goal: Last date of sale per segment

Latest Sale Date = 
CALCULATE(
    MAX('Sales'[Sale Date]),
    ALLEXCEPT('Sales', 'Sales'[Segment])
)