Drillthrough on Multiple Fields, then removing one of the filters in Power BI - powerbi

I have run into an interesting use case that has been causing some headaches.
Basically, the end user wants to be able to click on the month/category on a stacked column chart, drill through to show all items in that category, but then also show the values for every month.
The data model basically has two tables. One contains all the transactional detail (Table A).
The second table contains a monthly snapshot (Table B), with both being linked by an item-month key.
The snapshot contains the categories for each item/month combination. There is also a category on the snapshot for table B, "Idle", which by definition would not have values for the specific month on Table A.
So basically to frame it another way, I am wanting a measure that will do something like this:
For all items in the selected month/category of Table B, return all values from Table A.
Because the resulting visual will be drillthrough, I think it also will basically guaranteed be filtered by the status/month.
Any help on this would be appreciated, would be happy to clarify at all.
This is the code I had come up with so far. It appears to work in cases where data exists, but not situations where the aforementioned Idle items appear. (ex: an Idle Item may have values for 11/12 months, but trying to drillthrough on the period where it does not have values results in slicers not working on the drillthrough page, which may be another issue altogether)
The "DistinctDates" table is a disconnected date table containing each distinct year/month from table B.
Measure =
VAR MaxDate = MAX(DistinctDates[DATE])
VAR MinDate = MIN(DistinctDates[DATE])
Var Output=
CALCULATE(
SUM(TABLE_A[VALUE])
, FILTER(
ALLEXCEPT(TABLE_B, TABLE_B[ITEM]),
TABLE_B[DATE] >= MinDate
&& TABLE_B[DATE] <= MaxDate
&& NOT ISBLANK(SELECTEDVALUE(TABLE_B[ITEM]))
)
)
Return Output

Related

Power BI - Need a slicer to look at multiple columns of Data

I am learning PowerBI as i go along and have been able to solve most issues faced by a quick google. Unfortunately this problem has baffled me.
We have thousands of lines of data which include a "Home Country" column & "Away Country" column.
What we need our slicer to do is to is to pick up for example Australia in both of these columns and display the results.
I currently have a table created using the below:
slicercountrytable = distinct(
Union(
Values('All Data'[Home Country]),
Values('All Data'[Away Country])))'''
and then a measure:
Measure =
if(
Min('All Data'[Home Country]) in values (slicercountrytable[Country])
|| Min('All Data'[Away Country]) in values (slicercountrytable[Country]),
1,
Blank()
)
And have also tried the below measure:
Measure 3 = VAR
Searchvalue=search(SELECTEDVALUE(slicercountrytable[Country]),SELECTEDVALUE('All Data'[Combined Country]),,Blank())
Return
If(Searchvalue > 0,"Found")
I need the slicer to control the entire sheet however the above are doing nothing.
Thanks
In that case, instead of building some complicated DAX I suggest to work the model.
Let's say your current table looks like that:
id
home country
away country
1
A
B
2
B
C
You may want to deal with that in another table by unpivoting home_country and away_country in PowerQuery.
In order to have a country table like that:
id
country
attribute
1
A
home
1
B
away
2
B
home
2
C
away
Then you link this new table to your existing one on id and filter/slice in it.
I reproduced your example and feel that it is already showing the desired behavior. I think the problem you might be running into is that you will now need to add your 'measure' filter to each and every visual individually. It cannot be added to 'Page' or 'All Pages' filter areas. This is because of the way a measure's calculation varies across context and cannot be avoided.
DAX
Table 2 = distinct(union(all('Table'[Away]), all('Table'[Home])))
Measure =
if(
MAX('Table'[Away]) in VALUES('Table 2'[SelectedCountries])
|| MAX('Table'[Home]) in VALUES('Table 2'[SelectedCountries]) ,
1,
blank()
)

Show filtered data when no value is selected in slicer in power bi

I have two tables, once for slicer and other one is for details table. The details table have a InvoiceDate column where some rows have blank InvoiceDate. The slicer table looks like below:
The slicer will only show value of of ID 1, like below.
Initially I want slicer to be un checked and the data should show only rows where InvoiceDate is Blank. Once User select the Slicer as Include Invoiced Records, it should show both full details i.e. Rows with Blank + Non-Empty dates rows.
There are two other ways of doing what you want that are probably more 'correct' but I'll also describe a way to provide the behavior you describe.
Option one: Delete your second table. Add a calculated column to your details table as follows:
Invoice Status = IF (ISBLANK([Invoice Date]) = TRUE(), "Not yet invoiced", "Invoiced")
Create a slicer using [Invoice Status] and simply default it to show 'not invoiced.' If users want to see the invoiced records, they just check that box in the slicer as well.
Option Two: Use Bookmarks and buttons to produce the desired effect. Create two buttons, one that says 'Include Invoiced Customers' and another that says 'Hide Invoiced Customers' -- create two bookmarks where one has the invoiced customers filtered out of the visual and one where the invoiced customers aren't filtered. Set each button's "Action" to the appropriate bookmark.
Option Three Keep your 'slicer' table. Let's assume it's called 'Invoice Filter Selection.' Create a new measure:
IncludeDetailFilter =
IF (ISFILTERED('Invoice Filter Selection'[Value]) = True(),
1,
IF (ISBLANK(MAX(InvoiceDetails[Invoice Date])) = TRUE(), 1, 0)
)
When the slicer has a selection, it will be considered 'Filtered' and you will pass into the first branch of the IF where the measure always evaluates to 1. When the slicer isn't selected, the measure will evaluate to 1 or 0 depending on whether or not there are any values for Invoice Date in the row. Add this new measure as a filter on your invoice detail visual.
Unchecked:
Checked:
Hope it Helps.

Power Bi recalculate status of the store depending on Date Slicer selection

Please check the screenshots first:
I am having difficulty recalculating store status based on first date they had order depending on date slicer selection. To keep things simple I have: date table, store table and order data table. This task is tricky since I have 2 dimensional tables and 1 fact table and already have a date table connected to my order date on my fact table.
But now I need categorize my stores into new and old and the] kicker that it has to be dynamic:
For a selected period of time per slicer, the goal is to see new stores that had their first order date in the given period of year from slicer selection time.
ex: date selected was 04/2021 then I need to see all new stores which would have their first order date b/n 04/2020 and 04/2021 and stores that has order date prior to 04/2020 are no longer new, but old. If I bring a separate fact table with that calculation and make relationship b/n date table, I will not be able to connect to my order date fact table, which I need to.
A measure should be created to get the store's first order date using an ALL filter.
First Order Date = CALCULATE(MIN(Fact_Orders[OrderDate]), ALL('Date'))
So this measure can be used to classify the stores.
Store Classification =
IF
(
[First Order Date] >= DATE(SELECTEDVALUE('Date'[Date].[Year]) - 1, SELECTEDVALUE('Date'[Date].[MonthNo]), 1) &&
[First Order Date] < DATE(SELECTEDVALUE('Date'[Date].[Year]), SELECTEDVALUE('Date'[Date].[MonthNo]) + 1, 1),
"NEW",
BLANK()
)
This formula works only if one value is selected in a slicer as it uses SELECTEDVALUE. Instead you can also use MIN('Date'[Date]) and MAX('Date'[Date]).

Filter by last not blank date in Power BI

I have data from multiple countries on a monthly basis. Since the updates are not regular, I want to set up filter to visuals, so they would show the last month for which I have data from all the countries. I have data from each country loaded into a separate dataset, which then are merged into one big. Is there an easy way to place such filter? I managed to use "LASTDATE" function in each of country sets to find which date is last, but if I try to filter with that measure, I simply get nothing in a result. Thanks!
Well, this feels a little clunky to me but I believe it will work for you. There are two steps. The first is to create a summary table that reads through your data and counts the number of distinct countries that you have in each month. This will be a new table in your model, so go into the modeling tab, click 'New Table' and add this DAX. Obviously, correct for your table and column names.
SUMMARIZED_ROWS = SUMMARIZE(
'Table1'
,Table1[Month]
,"CountOfCountries"
,DISTINCTCOUNT(Table1[Country])
)
Now add a measure to the table (or anywhere) like this:
MonthWithMostCountries = CALCULATE(
LASTNONBLANK(SUMMARIZED_ROWS[Month], 1 )
, FILTER(SUMMARIZED_ROWS, SUMMARIZED_ROWS[CountOfCountries] = MAX(SUMMARIZED_ROWS[CountOfCountries]) ) )
This is going to give you the month where you have the most distinct countries in your data. You'll want to look at it in a card or similarly isolated visual as it is a measure and can be affected by filter context.
So, on the left is my mock data - 3 countries, 3 months each with a 1 month stagger. On the right you see the result of the Summarize table. Then the measure showing the final result.
Hope it helps.

Completing information in the table Power BI

I was hoping someone could help me with a part of the formula to get me to my end goal.
Table PR_HIST_MOVIM_PEDID:
Table LOG:
PR_HIST_MOVIM_PEDID table has order status per day, but when you turn the month, it loses information. A LOG table has one last transition of each request per day and it is this table that is the correct reference. I have to create a new table that shows me all the requests and their days without losing information as soon as the birthday turn-over happens.
Example:
NOTE: Notice that this is a small example. My database table has tens of thousands of values.
How to achieve the final result?
Table Log
First, create a new table that just has the dates that you want to use. I created a new table like this:
AllDates = CALENDAR(MIN(TableLOG[DTH_INCLUI_LOG]), MAX(TableLOG[DTH_INCLUI_LOG]))
Now write a measure like this:
Measure =
VAR CurrentDate = SELECTEDVALUE(AllDates[Date])
VAR MaxDate = CALCULATE(MAX(TableLOG[DTH_INCLUI_LOG]),
TableLOG[DTH_INCLUI_LOG] <= CurrentDate)
RETURN CALCULATE(MAX(TableLOG[VLR_NOVO]), TableLOG[DTH_INCLUI_LOG] = MaxDate)
You should now be able to create a matrix with the AllDates[Date] for the columns and the Ovitem_log for the rows with the Measure for the values.