Forum Discussion

hello_12345's avatar
hello_12345
Regular Visitor
1 year ago
Solved

Hours Comparison Using USERELATIONSHIP: Unable to Display Trend

Hi, Please support. I am doing a comparison of any two time periods using USERELATIONSHIP. Example:   base_vol = calculate(sum('fact_Rawdata'[total_s])) comparison_vol = calculate([base_vol],...
  • rohit1991's avatar
    1 year ago

    HI hello_12345 ,

     

    The main issue is that USERELATIONSHIP can override your base week context, so your trend visuals end up showing the wrong weeks. The best way to solve this is to use TREATAS in your measure. This keeps your X-axis (weeks) correct and maps your base weeks to the comparison weeks for the calculation.

    Here’s how you can write your comparison measure:

     

    comparison_vol =
    CALCULATE( [base_vol], REMOVEFILTERS(dim_Week_base[Year_wk]),
    TREATAS( VALUES(dim_Week_base[Year_wk]),
    dim_Week_comparison[Year_wk] ) )

     

    Keep your trend visuals aligned to the weeks you select, Show the correct comparison values for each week, And avoid the visual context issues that come up with USERELATIONSHIP.

  • jaineshp's avatar
    jaineshp
    1 year ago

    Hi hello_12345 ,


    Yes, TREATAS can be used, but ensure:

    1. TREATAS maps correctly: TREATAS(VALUES(BaseTable[Column]), ComparisonTable[Column]) is right.

    2. Relationships: Underlying relationships (active or inactive with USERELATIONSHIP) are consistent with what TREATAS expects.

    3. Filter Context: REMOVEFILTERS might be too broad; consider ALLEXCEPT or ALLSELECTED if you need to preserve some context.

    Your USERELATIONSHIP approach was often simpler for comparisons if the relationships are set up. TREATAS is powerful but can be tricky with complex filter contexts.

    Key thing: The base_vol calculation itself needs to be correctly picking up the dim_Week_comparison and dim_b_comparison filters via TREATAS or USERELATIONSHIP. If base_vol is not reacting, it implies the filter context from the comparison tables isn't reaching it.