Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

creating a dynamic table in Power BI

Hi Experts

I am trying to creat the following in Power BI for the Y Values (dates) as shown in the image below. The image below is an example that someone has done in excel. The question is how would you do this in power BI

 

image 1.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

i just need the result from the table which in excel is sum D4:015 = -44 (based on material_id using my data set) 

 

Date Table in Power BI

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

sample power bi file.

https://www.dropbox.com/s/1jq4ddeuy3nxpzq/apples.pbix?dl=0

 

 

 

  • If the error message is about SUMMARIZECOLUMNS and ADDMISSINGITEMS not being allowed in the current context, that's an issue with SUMMARIZECOLUMNS not playing well with slicers on multiple columns.

     

    I re-wrote the measure to use the old ADDCOLUMNS style pattern that was used before SUMMARIZECOLUMNS was introduced:

    MK-Stat = 
    VAR ComplaintsByFiscalMo = ADDCOLUMNS(VALUES(PMS_COMPLAINT[FISCAL_MON_START_DT]),"CountComplaints", CALCULATE(COUNTROWS(PMS_COMPLAINT)))
    RETURN
    SUMX(ComplaintsByFiscalMo, 
        SUMX(ComplaintsByFiscalMo,
            IF([FISCAL_MON_START_DT]>EARLIER([FISCAL_MON_START_DT])&&[CountComplaints]>EARLIER([CountComplaints]), 1,
            IF([FISCAL_MON_START_DT]>EARLIER([FISCAL_MON_START_DT])&&[CountComplaints]<EARLIER([CountComplaints]), -1))
        )
    )

    I've also re-uploaded the change in the .pbix file on Google Drive. The same link will download the newer version.

  • Anonymous's avatar
    Anonymous
    7 years ago
    Hi thanks for the excellent feedback. I'll have to post another question as I have just applied your calculation in the SE for and the Z test as per link and I am getting a different p value to the one showing in the main fact table in column mannkandelY. See what se and z test values u get as per link.

19 Replies

  • Cmcmahan's avatar
    Cmcmahan
    Resident Rockstar

    The formula seems pretty easy. Take the count of rows that are below than the current row, and evaluate them for positive/zero/negative results.  To break it down, if all you have is the data in A4:A15, get a count of values that have a higher row# and that are higher than the current value, and subtract a count of values that have a higher row# and are lower than the current value.  Repeat for each row.

     

    My question is how is the order of the data determined?  Right now, it seems arbitrary, but changing the order would definitely give a different result. In this pseudocode, I've just given a numerical index to each data point, to keep the order as you presented it.  You can replace that with any sortable column that indicates the order of the values.

    MKSum = 
    SUMX(
        'Data', 
        CALCULATE(COUNTROWS(FILTER(ALL(Data), Data[Index]>SELECTEDVALUE('Data'[Index]) && Data[Value] > SELECTEDVALUE(Data[Value])))) -
        CALCULATE(COUNTROWS(FILTER(ALL(Data), Data[Index]>SELECTEDVALUE('Data'[Index]) && Data[Value] < SELECTEDVALUE(Data[Value]))))
    )

    Here's the data table I used to get a result of -44:

    Data:

    ValueIndex
    6.81
    5.92
    5.73
    5.54
    5.55
    4.56
    47
    5.18
    4.59
    4.510
    3.311
    4.812
    • Anonymous's avatar
      Anonymous
      Not applicable
      Many thanks for the amazing feedback. My question is how would I do that for my Y values in table above. Dates starting at 1.7.2018 to 1.6.2019.l for the provided data set using column MATERIAL_ID.. OR am I complete mad to use material Id..
      Note as I move in August 2019 may dates change from 1.7.2018 to 1.8.2019 and 1.6.2019 to 1.17.2019 for period 12.
      • Cmcmahan's avatar
        Cmcmahan
        Resident Rockstar

        What is a "Y value" from the table above? A year value? Some sort of calculated value? The data table you shared looks like a date dimension, so doesn't have any Material ID associated with the data, nor any actual data to calculate a "Y value" from.

         

        You're fine using MATERIAL_ID as your sorting column, as long as that's the order you want the data in. I would have assumed that MATERIAL_ID is more of a group by field as opposed to an ordering field, but it could be both.  From your original example, I wasn't sure why 6.8 came first, and 5.9 second.  If that's because the MATERIAL_ID for 6.8 is less than the MATERIAL_ID of 5.9, that's fine.

         

        Changing the date range of the current period should work fine for whatever visual you have, since that will limit the input data.

         

        I would try and help more directly with the .pbix you shared, but there's SO MUCH data in there, I don't know what fields to use for what.  That's why my previous answer used the very simple data set with 12 values that you shared.  You should be able to just replace Data[Index] and Data[Value] with the fields/measures that you actually want to use for calculations.

    • Anonymous's avatar
      Anonymous
      Not applicable
      The above was an example. Re My question is how is the order of the data determined? In my data set using material_id