cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User I
Super User I

Re: Current vs Previous value, not dependent on base value

Yes, it has a little to do with the data structure.  You will need to create another table with a single column and the values that you want shown in your slicer (often "Enter Data" is the way to do this).  Once you have that table, create MType against that table.

type.png

2018-12-17 07_36_54-new scratchpad - Power BI Desktop.pngdata.png

 

MType = SELECTEDVALUE(SaleType[Type])

TotAmt =
SWITCH (
    [MType],
    "Customer", SUM ( SalesTab[Customer] ),
    "Invoice", SUM ( SalesTab[Invoice] ),
    "Sale Amount", SUM ( SalesTab[Sale Amount] )
)

Customer.pngInvoice.pngSale Amount.png

 

Hope this makes sense.

David

 




Proud to be a Super User!




Highlighted
Anonymous
Not applicable

Re: Current vs Previous value, not dependent on base value

Thank you so much for the help! 

 

The Slicer is working now! 

 

When I try to do the comparison that was mentioned earlier I get an error for this part:

Measure Delta = var __SelectedMeasure = 
SWITCH (
[MType];
"bla bla"; AVERAGE(Table[Value]);
etc etc
and then the error here (underlined):
var __PDMeasure = CALCULATE((__SelectedMeasure; PREVIOUSDAY(Blad1[Tid])) RETURN __SelectedMeasure - __PDMeasure;

This Measure is made inside the table containing the values and time.

The MType measure is inside the second table 

MType = SELECTEDVALUE(SelectValue[ValueSelect]) 

The syntax for 'RETURN' is incorrect. (DAX(var __SelectedMeasure = SWITCH( [MType], "BJ-HÖ1 etc etc...

 

 

 

 

Highlighted
Super User I
Super User I

Re: Current vs Previous value, not dependent on base value

Without seeing the entire code, it's hard to tell.  Likely an extra ) somewhere in the SWITCH statement.  Or it could be the ; at the end of RETURN.  Can you post the entire measure code (you can replace the slicer values with XXX if need be as the actual values should be immaterial) ?

 

Also, doublecheck that it's a measure not a calculated column.




Proud to be a Super User!




Highlighted
Anonymous
Not applicable

Re: Current vs Previous value, not dependent on base value

It was indeend an extra paranthesis... but I only get a "0" returned as a resulst in the graphs

 

Measure Delta = var __SelectedMeasure = 
    SWITCH(
        [MType];
        "BJ-HÖ1"; AVERAGE(Blad1[BJ-HÖ1]);
        "BJ-MÄ"; AVERAGE(Blad1[BJ-MÄ]);
        "BJ-TS1"; AVERAGE(Blad1[BJ-TS1]);
        etc
    )
    var __PDMeasure = CALCULATE(__SelectedMeasure; PREVIOUSDAY(Blad1[Tid]))

    RETURN __SelectedMeasure - __PDMeasure

I then have measure called Disp that is the same as the code above without the vars and Return, så just the switch between the values.

 

In the second table i have:

MType = SELECTEDVALUE(SelectValue[ValueSelect]) 

and the column with the names of the different value "categories" (as seen in the code, BJ-HÖ1 etc)

 

The Slicer is coupled with this table column (Called ValueSelect) and properly changes the displayed values in my chart. 

 

So maybe I missunderstood something regarding where to put the calucation vars? 

 

 

 

Highlighted
Super User I
Super User I

Re: Current vs Previous value, not dependent on base value

"The Slicer is coupled with this table column (Called ValueSelect) and properly changes the displayed values in my chart. "

 

If by "coupled" you mean "having a relationship in the model", you do not want the slicer value table to have a relationship with the fact table.  The slicer table is independent of anything else so it doesn't introduce any extra filters.

 

It shouldn't matter where the measures live, but best practice would be to put it either on the fact table (Blad1) or in a separate Measures table.

 

One other thing I notice is that you are using PREVIOUSDAY() on the date field that is on the fact table.  PREVIOUSDAY() (and most of time intellegence functions) should be done against a Date table that has a 1-to-many relationship to the fact table.  CALENDARAUTO() is the quickest way to make a Date table if you don't already have one.




Proud to be a Super User!




Highlighted
Anonymous
Not applicable

Re: Current vs Previous value, not dependent on base value

Thank you for the speedy replies 🙂 

 

Maybe coupled was a poor choice of words, I meant that it is selected in the slicer, 

Select.PNG

 

So if I understood right, I made a new table using calendarauto and gave it a 1 - * relationship with the table containing my "original" time column and the values. 

kardinalitet.PNG

 

but when I use this new tables date column I get a blank image on my chart? The Original time still works. 

Highlighted
Super User I
Super User I

Re: Current vs Previous value, not dependent on base value

Is Blad1[Tid] meant to be a time value or a date+time value or something else?




Proud to be a Super User!




Highlighted
Anonymous
Not applicable

Re: Current vs Previous value, not dependent on base value

Date and time, YYYY-MM-DD HH-MM:SS every value is from 02:00:00

Highlighted
Super User I
Super User I

Re: Current vs Previous value, not dependent on base value

At this point I don't know if I can go further without seeing a copy of your actual PBIX file.  If you can remove or mask sensitive data and put it on a sharing site, I can get a copy and see what is going on.

 

Alternatively, with a sample of data and a view of the model I may be able to reconstruct it without the need for you to send the entire thing.




Proud to be a Super User!




Highlighted
Anonymous
Not applicable

Re: Current vs Previous value, not dependent on base value

Hi, 

Thank you for your continued help, 

 

I made a version with new names, I've uploaded the file to dropbox: PBIX file

 

Thanks

Helpful resources

Announcements
Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors