Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Chart comparing two user selected series

I have a table of commodity price time series data with the following columns:

Date (date of price observation)

Commodity

Period (delivery period for commodity)

Price

 

I would like to create a power BI page (which I can upload to the server) which allows the user to select two time series by selecting Commodity and Period for each series, and then plots the delta between the two prices on a chart. For example they might choose Jan-23 Wheat and Jan-24 Wheat and it would plot the difference between the two prices on each date.

 

I was reading about using parameters but apparently these cannot be published. Is there another way?

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    Please create a measure with below dax formula:

    Measure =
    VAR _a =
        SELECTEDVALUE ( 'Table 2'[Period] )
    VAR _b =
        SELECTEDVALUE ( 'Table 3'[Period] )
    VAR _c =
        SELECTEDVALUE ( 'Table'[Commodity] )
    VAR _d =
        SELECTEDVALUE ( 'Table'[Date] )
    VAR val1 =
        CALCULATE (
            MAX ( 'Table'[Price] ),
            'Table'[Date] = _d,
            'Table'[Period] = _a,
            'Table'[Commodity] = _c
        )
    VAR val2 =
        CALCULATE (
            MAX ( 'Table'[Price] ),
            'Table'[Date] = _d,
            'Table'[Period] = _b,
            'Table'[Commodity] = _c
        )
    RETURN
        val2 - val1
    

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Please create a measure with below dax formula:

    Measure =
    VAR _a =
        SELECTEDVALUE ( 'Table 2'[Period] )
    VAR _b =
        SELECTEDVALUE ( 'Table 3'[Period] )
    VAR _c =
        SELECTEDVALUE ( 'Table'[Commodity] )
    VAR _d =
        SELECTEDVALUE ( 'Table'[Date] )
    VAR val1 =
        CALCULATE (
            MAX ( 'Table'[Price] ),
            'Table'[Date] = _d,
            'Table'[Period] = _a,
            'Table'[Commodity] = _c
        )
    VAR val2 =
        CALCULATE (
            MAX ( 'Table'[Price] ),
            'Table'[Date] = _d,
            'Table'[Period] = _b,
            'Table'[Commodity] = _c
        )
    RETURN
        val2 - val1
    

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Hi Anonymous 

    You can achieve it easily using 2 calendar tables.

    Please attach some data table to work with and the desired result and I will show you how.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Many thanks! So say I have data like the table below. Roughly what I'd be looking for is this:

     

     

     

     

     

    DateCommodityPeriodPrice
    20-Jan-23WheatJan-2349.45
    21-Jan-23WheatJan-2349.54
    22-Jan-23WheatJan-2350.46
    23-Jan-23WheatJan-2351.04
    20-Jan-23WheatJan-2449.92
    21-Jan-23WheatJan-2450.01
    22-Jan-23WheatJan-2450.26
    23-Jan-23WheatJan-2451.20
    20-Jan-23CornJan-2338.19
    21-Jan-23CornJan-2338.69
    22-Jan-23CornJan-2339.68
    23-Jan-23CornJan-2340.18
    20-Jan-23CornJan-2439.01
    21-Jan-23CornJan-2439.23
    22-Jan-23CornJan-2439.61
    23-Jan-23CornJan-2440.42