Sumif using page, report and visual level filters - powerbi

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..

Related

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.

Default Silcer Selection in Power BI (latest date)

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.

Create a pivot table in Power BI with dates instead of aggregate values?

I have a table of companies with descriptive data about where we are in the sales stage with the company, and the date we entered that specific stage. As can be seen below, the stages are rows in a Process Step column
My objective is to pivot this column so each Process Step is a column, with a date below it, as shown in excel:
I tried to edit the query and pivot the column upon loading it, but for the "aggregate value" column, no matter which column I use as the values column, it results in some form of error
My advice would be not to pivot the table in the query and use measures to get dates that you want. The benefit of not doing so is that you are able to perform all sorts of other analytics. For instance, Sankey chart would be hard to do properly with pivoted table.
To get the pivot table you are showing from Excel, it's as simple as using matrix visual in Power BI and putting Client code in rows and Process Step in Columns, then Effective date in values.
If you need to perform calculations between stages, it's also not too difficult. For instance, you can create a meausure that shows only dates at certain stages, another measure for another stage, and so on. For example:
Date uploaded = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Upload"))
Date exported = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Export"))
Time upload to export = DATEDIFF([Date uploaded], [Date exported], DAY)
These measures will work in the context of client and assuming there is only one date for the upload step (but no Process step in rows or columns). If another scenario is needed, perhaps a different approach could be taken.
Please let me know if that solves your problem.

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:

Is it possible to use a slicer as a parameter to a DAX Summarize function?

I have a FactLosses Table, and a DimAccumulation table. I have brought them into PowerBi and I have placed a slicer to choose which accumulation zones i am interested in.
Once the user has selected the zones, i want to perform a group by year on the losses and sum the losses into year buckets. But only on the data that applies to the zones the user picked.
I am using the following DAX code to do the group by like so...
Table = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
The problem is the new table always produces the same result. i.e When i make changes to which accumulation perils should be included it makes no difference to the summation. (it is summing the entire table)
I'd like to use the slicer to filter the fact table and then have the DAX query run on the filtered list. Is this possible?
If you want these tables to be responsive to filters or slicers on your report, then you can't write these as calculated tables that show up under the Data tab since those are computed before any filtering happens.
To get what you want, you have to do everything inside of a measure, since those are what respond to slicers. If you're looking for the max loss year once the grouping and summing are completed, you can write a measure along these lines:
Year Max =
VAR CalculatedTable = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
RETURN MAXX(CalculatedTable, [Losses By Year])
Writing it this way will allow the calculated table to respond to your slicers and filters.