Default Silcer Selection in Power BI (latest date) - powerbi

I have one query can somebody please tell how to show Latest date in a date format
So basically, I want to show the latest date selected by default and if the user wants to select other dates they can change manually but the latest date should be in a date format
Date = IF('Query'[Date] = MAX('Q'[Date]), "Latest Date", FORMAT('Query'[Date], "MM-DD-YYYY"))
Please help to show the latest date in a date format
eg: MM-DD-YYYY

First of all, unless you use a static value like "Latest Date" as you have done in the column above, you will not be able to set the slicer to the latest date. However, you can have your report behave as though the latest date were selected if nothing is selected.
Based on your formula, I am assuming that the table Query holds the static latest date of the model and that the table Q is your calendar table.
Create these measures:
Pivot Date = MAX(Query[Date])
Earliest Selected Date = IF(ISFILTERED(Q[Date]),MIN(Q[Date]),[Pivot Date])
Latest Selected Date = IF(ISFILTERED(Q[Date]),MAX(Q[Date]),[Pivot Date])
Now the hard part is you need to write all your measures to use the date range defined by Earliest and Latest Selected instead of just leaving it up to the slicer to control the dates. This allows you to control what's displayed when nothing is selected.
ExampleMeasure =
var start_date = [Earliest Selected Date]
var end_date = [Latest Selected Date]
return
CALCULATE([Some Measure], removefilters(q[date]), q[date] >= start_date, q[date] <= end_date)
One of the drawbacks of this approach is that you may be depending on your slicer to show the user which dates are selected. To overcome that, add an unobtrusive visual that shows the dates in use. I like to use a Multi Row Card for this and place it in the top right corner of every page. I include these measures: Available From, Available to, Selected From and Selected To. That way viewers know how much data is in the report overall, and they know what's selected at this time. Placing this in the same place on every page in every report is an excellent practice as your viewers will become habituated to consulting this spot for date info.
Finally, I want to point out that you could implement this logic with calculation groups, and that is how I would do it in one of my own reports. Doing so would eliminate the need to modify all the measures you already have, but it would introduce a number of complexities. Calculation Groups have a big learning curve, so you need to be prepared for that journey. The alternative I have suggested will be quicker than getting up to speed on Calculation Groups. However, you should learn how to use them. I highly recommend everything at sqlbi.com on this topic. They have an excellent search tool on the site to find all their content related to Calculation Groups.

Related

Power BI DAX: date slicer filter does not affect custom measure that uses CALCULATE

I am struggling to understand the behavior of the filter slicers and custom measures when using the CALCULATE DAX formula. My goal is pretty simple: I have a sales table that includes both the sales date and the ship date (see the below screenshot), and I have created two custom measures:
Sold products = CALCULATE(
COUNT('dummy data'[SaleID])
)
Shipped products = CALCULATE(
COUNT('dummy data'[SaleID]),
NOT(ISBLANK('dummy data'[Ship date]))
)
Note that the table will always have a sale date but may not have a shipping date (yet), also shipping date will always be a "past date".
I have added a filter slicer in the canvas using the 'dummy data'[Ship date] column (note that is the same field I am using on my Shipped products measure).
When I attempt to use the date filter slicer (e.g., shipped products between two specific dates), the Shipped products measure does not change based on the filters applied.
Why does this happen? I would appreciate any extensive explanation that may help me understand the behavior of this scenario and, ideally, a solution of how I can make this work, how I can use the filter slicer for the Ship Date at the same time it is being used as part of the CALCULATE filter condition.
Table:
Canvas report without filter slicer
Canvas report with specific date range applied on filter slicer:
Expected result: Shipped products should be 7
Thanks
You're overwriting the filter context in your measure.
CALCULATE() is used to overwrite the filter context and the part that says:
NOT(ISBLANK('dummy data'[Ship date]))
is overwriting that context. Also, for it to respond to slicers, you'll need to use ALLSELECTED() at some point.
You should really be using a date table too.
In your specific case, a simple measure like this will work and respond to slicers.
Shipped products = COUNT('dummy data'[SaleID])
I suggest you read more about CALCULATE() here:
https://www.sqlbi.com/articles/introducing-calculate-in-dax/

How do I hold a slicer selection static in Power BI / DAX?

I can illustrate the issue here in Power BI. I need the selection on Date to stay static.
We audit widgets every day and look for certain quality control "issues". I have a slicer on Audit Date, and a calculation meant to return the Total Number of Distinct Units Audited within that date range. The correct value is 413 for May 17 - June 2.
However when I select a Quality Control Issue from the list, it changes my calculation. The calculation should NOT be affected by a selection on Issue, however it’s putting in an “Included” filter and then throwing out days where we didn’t audit a widget with that particular issue – see how 5/17, 5/20 and 5/23 dropped from the list whenever I click "Dent" in the table? However 413 correctly remains in the table.
I need the calculation to return 413, even when Issues are selected from a slicer or table. I thought I addressed the with the ALL() filter, but it's not behaving as I expected it to.
Note: I need to alter the CALCULATION – NOT the INTERACTIONS. The calculation is used outside of visuals.
Thank you.
Either turn of Visual Interactions in the report, or write a measure using the mighty CALCULATE function to ignore selected filters.
Once you've removed the filters you can re-apply any you want to keep, eg
totalunitsaudited =
var minDate = min('Date'[Date])
var maxDate = max('Date'[Date])
return
calculate(DISTINCTCOUNTNOBLANK(Audits[SerialNo]),
all(Audits),
Audits[Audit Date] >= minDate && Audits[Audit Date] <= maxDate)
Also here you need a date table. You can create one with the CALENDARAUTO DAX function:
Date = CALENDARAUTO()
When you put the slicer on the Audits[Audit Date] you've got automatic cross-filtering between the date and the Issue. With the slicer on a separate date table you can control whether filters on Audits flow back to the Date table.

Power BI visualization of data with a Start and End date

THis is an example of what I think i need to do
I would like to ask some modeling advise I cannot solve myself:
I am using Power BI to visualize the time machinery is out of order.
The source is a register of equipment not functioning, with a start date and end date (note that there is no end date if the machine is not fixed yet).
I would like to show the time (hours, percentage, etc) that the machinery is out of order, filter for a specific period /date (e.g. month).
So I have 2 date columns: ‘’Start out of order’’ and ‘’Back in order’’
I do have a date table, which I usually would connect to all the date variables. However, since I am working with a Start and End date. This does not give the result I am looking for.
Any help is very much appreciated!
Kind regards,
Link to my Power BI FILE:
https://wetransfer.com/downloads/83ca3850392967d0d42a5cc71f4352c420200213160932/eb7353
Stijn
I am not sure how you would like to visualise your data, but this is what I managed to do:
create a daysdiff column with
Daysbetween = IF(ISBLANK(TF_Eventos
[End out of order]);DATEDIFF(TF_Eventos[Start out of
order];TF_Eventos[TODAY];HOUR);DATEDIFF(TF_Eventos
[Start out of order];TF_Eventos[End out of order];HOUR))
This creates your column to check difference between Dates.
Then create a separate column with your Date. In this case I copied the Start out of order date, since I thought you might wanted to be able to filter for the start dates. Then simply create a relationship between your newly created Date column and your start out of order date.
Doing so lets you create a visual with the daysbetween (in this case portrayed in hours) and your start dates. Now just simply add a slicer and you can filter on date.
Hope this helps

Sumif using page, report and visual level filters

I have two tables that are related by an ID column called 'Program_Code' (1:Many).
'Program_Summary':
Program Code = each row has a unique ID, e.g. HI-18, HI-17
Program Name = name of a program, e.g. Home Improvement
Incentive Spending = calculate(sum(Program_Data[Incentives]))
'Program_Data':
Program Code = many rows with the same ID
Incentives = incentive amount to summarize in Program Summary table
Record Status = Claimed, Pipeline or Rejected
Record Fiscal Year = 2017, 2018 or 2019
I created a Power BI table that has rows organized by 'Program Name'. Note that each program name like "Home Improvement" may have more than one code associated with it, e.g. HI-18 and HI-17 corresponding to fiscal years.
I'm hoping to summarize Incentive Spending by program name, and use page/report level filters to restrict results. The Report Level filters are:
Record Fiscal Year = 2017
Record Status = Claimed
But, the calculate(sum(Program_Data[Incentives])) filter ignores these page level filters. How do I fix this?
You created "Incentive Spending" as a calculated column. Instead, you need to create it as a measure.
Calculated columns are calculated only once - when you create them, or when you reload data. After that, calculated columns contain only static data, and can not respond to any filters.
Measures, on the other hand, are dynamic formulas that recalculate any time you change any filters.
To fix your problem, simply create a new measure from "Modeling" tab:
and add DAX code:
Incentive Spending = SUM(Program_Data[Incentives])
(no need to use CALCULATE here).
Drop this measure into a table or matrix, and it should work. Instead of page/report level filters, I'd recommend to use slicers - create a slicer for Fiscal Year, and another slicer for Record Status. They will allow you to filter the calculation with ease.
You can use:
CALCULATE(sum(Program_Data[Incentives]);Program_Data[Record Fiscal Year] = 2017 && Program_Data[Record Status] = "Claimed")
However, I do not understand why you would need this because you have 2 tables with the right link, this should give you all possibilities with the table/matrix visualization what you need to show correct results..

Change column values based on slicer selection

Using PowerBI desktop, I have created a small table (called TimeSelector), with three elements: Day, Week and Month
The idea is to use the content of this table to create a slicer with three options
Thus, selecting one of those options should change the way dates are used in tables.
For instance, selecting Day would result in the following table:
While selecting Week would result in this:
Etc..
I have tried to write a new measure taking in account the selected slicer element, but it is not working:
DayWeekMonthSelection = IF(CONTAINS(TimeSelector;TimeSelector[DayWeekMonth];"Month");
MONTH(VALUES('uptime_downtime'[Uptime_date])))
This is only the first part of the formula, only testing the month option as a start.
Any idea on how to do this?
To offer another perspective:
The approach I take with this is to have a separate table in the database - containing meta data about the date, called date_lookup.
2 of the fields in this table are FirstDateOfMonth & FirstDateOfWeek.
Some of the other fields are lastDateOfMonth & LastDateOfWeek, also DayOfWeek.
By using these fields I can easily present visuals that are grouped by month or week.
Sure you can use functions to get this information, but functions can be platform dependant. If you're making a join to the date_lookup anyway - it's no more effort to get this info from there...
The main reason we need to store this meta data is our company Financial year is Jul - Jun. Therefore we need to have available the Correct FY - which is stored as a field in the date_lookup table. I also have fields in there identifying public holidays...
This is an interesting question, but I'm not sure how to do exactly what you are asking for, so I'll suggest an alternative. (Changing a measure based on a slicer selection isn't too difficult, but I'm not sure a good way to swap out a field/dimension.)
Instead of creating a separate table for your slicers, a different possible approach would be to create a date hierarchy. Often when you drag a date column into the rows or columns box it will automatically create a date hierarchy with Year/Quarter/Month/Date, but since you want week and not quarter, let's create one manually.
First, create a couple calculated columns for week and month. For example:
Month = FORMAT(uptime_downtime[Date], "mmm")
Week = WEEKNUM(uptime_downtime[Date])
Now right-click on the date on the fields, and choose New Hierarchy. It should look like this now:
Now drag the Month and Week columns onto Date Hierarchy and then rearrange them in the appropriate order:
Now you can use that hierarchy in a matrix and use the drill up and down buttons
to get the different groupings: