Forum Discussion

jaryszek's avatar
jaryszek
Icon for Super User rankSuper User
7 months ago
Solved

Auto-scale Daily/Monthly axis with field parameter – chart still shows wrong grain

I’m trying to get a line chart axis to automatically show either Date (daily) or MonthName (monthly) based on the selected date range, using a field parameter and an auto-scale measure. Setup: Da...
  • jaryszek's avatar
    6 months ago

    Ok I solved the issue myself. 

    Auto-Scale Date Filter = 
    VAR MinDate =
        CALCULATE (
            MIN ( 'dim_date'[Date] ),
            ALLSELECTED ( 'dim_date' )
        )
    
    VAR MaxDate =
        CALCULATE (
            MAX ( 'dim_date'[Date] ),
            ALLSELECTED ( 'dim_date' )
        )
    
    VAR DayCount =
        DATEDIFF ( MinDate, MaxDate, DAY ) + 1
    
    VAR MonthCount =
        DATEDIFF ( MinDate, MaxDate, MONTH )
    
    VAR Selection = [Date Hierarchy Selection]
    
    // Daily = up to 31 days
    VAR DailyScale =
        Selection = "Daily"
            && DayCount <= 31
    
    // Monthly = between 2 and 11 months
    VAR MonthlyScale =
        Selection = "Monthly"
            && MonthCount >= 1
            && MonthCount < 12
    
    RETURN
        IF ( DailyScale || MonthlyScale, 1, 0 )

     

    Dax was not working.