Selectively displaying data into the Long Text Viewer - powerbi

I have four levels of report filters: Month, Year, Region and Country, all of which were set as Page Level and Report Level filters.
The data is structured like so:
And basically, this is how it looks like if all slicers are set to All:
This is obviously not helpful and doesn't really give proper context to the data if viewed by anyone since it just listed down everything in the Comment column.
So is it possible to selectively display data from the Comment field into the Long Text Viewer (ie: display nothing if all Slicers were set to All, only display comments for the particular country/month, etc.)?

Depending on how you want the exact display logic to be, you may find the HASONEFILTER() and HASONEVALUE() function useful in this case.
The following is an example where a new measure is created, and it'll display the comment (concatenated by newline which will be handled later) when there are any filters applied to the column Month, Year or Country; or it'll return an empty string.
Useful comment =
IF(
HASONEFILTER(Data[Month]) || HASONEFILTER(Data[Year]) || HASONEFILTER(Data[Country]),
CONCATENATEX(Data, Data[Comment], "\n"),
""
)
The Long Text Viewer provides a format option called Newline starts with, which allows us to split the measure we created (which is a long concatenated string containing all filtered comments) back to separate lines for display purpose.
The following shows the result when no filter is applied:
The following shows the result when filter is applied:
EDIT:
Same result when slicer is a dropdown:
Another example, display nothing when year is 2016:
Useful comment 2 =
IF(
CONTAINS(DATA, DATA[Year], "2016"),
"",
CONCATENATEX(DATA, DATA[Comment], "\n")
)
When Year = 2016:
When Year = 2017:

Related

PowerBi Dax - Create a Measure that ignores applied filters and display in barchart

In my data I have two columns of date - claim registration date and resolved date. My report is using resolved date as a slicer filter. I would like to build a bar chart showing registered claims by client segments. I have tried several approaches and functions but they all return single count value. What I want is actual counted values for each type.
BySegmentRegistered = CALCULATE(COUNT(claims_data[client_id]),claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear])),ALL(claims_data))
BySegmentRegistered = CALCULATE(COUNT(claims_data[client_id]),FILTER(ALL(claims_data),claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear]))))
I have tried above code and several other iterations but they all return single value across all client_segments. If I simply do COUNT(claims_data[client_id]) than it displays count by each segment but date is wrong, hence it doesnt work for me.
Any ideas?
EDIT:
I just tried this and it works.
BySegmentRegistered = CALCULATE(COUNT(claims_data[cliend_id]), claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear])), REMOVEFILTERS(DateTable[MonthYear]))

PowerBI Matrix Visual - Replacing Blank with Zero (harder than I thought)

I am trying to replace blanks with zero in a matrix visual, but the traditional method of adding +0 is causing another problem. I have the case described below in detail. Thank you so much for any help anyone may be able to offer!
I have a (fictitious) company with 60 employees located in 5 regions (Midwest, Northeast, Pacific, and Southwest). Each employee holds an occupational type (such as chemist, auditor, geologist, truck driver, etc.). Across the entire company, there are 18 different occupational types.
Additionally, each region considers some of the occupations as critical and others as non-critical and the critical vs. non-critical occupation types vary by region. If the occupation is critical for a particular region, the occupational title (e.g. chemist) should appear in the visual and if the occupation is non-critical, the generic title ‘Non-Critical’ should appear instead of the occupational title.
To accomplish this, my PowerBI model has two related tables – employee list (dimension table/many) and occupation list (fact table/one). Each employee on the employee list has a match code that is related to the match code on the occupation list to determine if the occupation is critical or non-critical for that employee’s region. If the occupation is critical, the related field (that will be used on the row field of the visual will be the occupational title. If non-critical, the related field will be the generic title ‘Non-Critical’.
Here’s an example of three records from the employee list fact table:
Image A
And here’s an example of some records from the occupational list dimension table:
Image B
The purpose of the visual is to show the count of employees onboard at two points in time (called FY20 and FY21) by occupational type with a slicer to filter by region.
The employee count is produced using the measure =COUNTROWS(Employee List)
Everything works great at this point. Here is an example of the visual filtered to Midwest, which correctly shows the Midwest Region’s 10 critical occupations broken out by occupational title and the employee counts. (non-critical count also correctly shown)
Image C
And as a second example, here is the view filtered to the Pacific Region showing the Pacific’s 3 critical occupations (non-critical also correctly show):
Image D
My only goal with this visual is to display zero instead of a blank for those cases where there are no employees. When I modify the measure to:
=COUNTROWS(Employee List) + 0
I get the following result (filtering to Midwest for example):
Image E
So, the result is that the formula did replace the blanks with zeros, but now all the entire company’s 18 critical occupations are displayed and not just the 10 for the Midwest. The counts are still correct for the Midwest, but I only want to show the Midwest occupations as they were appearing correctly before I added +0 to the measure. If I try to simply filter them out at the visual level, then they will stay filtered when I switch region where they should be unfiltered.
It seems the behavior is that a blank being replaced by a value (0) means that when there is a combination for which there is no data (such as Midwest/Chemist), the visual will still show 0 as a result for that combination.
I’m looking for anything I can do to replace blanks with zero and not displace the occupation types that don’t apply for the region. I would appreciate any assistance as I’ve been thinking about this for hours and have hit a wall.
Thank you!
I suggest a measure on the following form, written verbosely:
# Employees w/ zeroes =
VAR _employees = [# Employees]
VAR _totalEmployees = CALCULATE ( [# Employees] , REMOVEFILTERS ( 'Employee List'[Year] ) )
RETURN
_employees + IF ( ISNUMBER ( _totalEmployees ) , 0 )
This will first check that the occupation type has employees for the selected filter context, and only tack on a zero if so. The column specified in REMOVEFILTERS() must correspond to whatever you are using in your visualization - it is used to modify the filter context.
It looks like a fairly simple (if possibly temporary) solution is available for this problem by using conditional/advanced filtering on the visual. I set the advanced filter to show when the value is not 0 and this seemed to take care of it. Thank you for the DAX code and I will explore those options as well.
Thanks again!

Power BI - Creating a calculated table

I am creating a dashboard in Power BI. I have to report the executions of a process in a daily basis. When selecting one of these days, I want to create another calculated table based on the day selected (providing concrete information about the number of executions and hours) as it follows:
TABLE_B = FILTER(TABLE_A; TABLE_A[EXEC_DATE] = [dateSelected])
When [dateSelected] is previously calculated from the selected day as it follows:
dateSelected = FORMAT(FIRSTDATE(TABLE_A[EXEC_DATE]);"dd/MM/yyyy")
I tried a lot of alternatives as, for example, create individualy the year, month and day to later compare. I used the format in both sides of the comparation, but none of them works for me. The most of the cases it returns me the whole source table without any kind of filters. In other cases, it doesn't return anything. But, when I put a concrete day ...
TABLE_B = FILTER(TABLE_A; TABLE_A[EXEC_DATE] = "20/02/2019")
... it makes the filter correctly generating the table as I want.
Does someone know how to implement the functionality I am searching for?
Thanks in advance.
You're almost there Juan. You simply need to use dateSelected as a varialbe inside of your DAX query:
TABLE_B =
var dateSelected = FIRSTDATE(TABLE_A[EXEC_DATE])
return
FILTER(TABLE_A, TABLE_A[EXEC_DATE] = dateSelected)
Note that all my dates are formatted as Date so I didn't need to use a FORMAT function.
Here's the final result:
I admit that this behavior can be quite confusing! Here is a useful link that will help you understand Power BI's context:
https://community.powerbi.com/t5/Desktop/Filtering-table-by-measures/td-p/131361
Let's treat option 1 as FILTER(TABLE_A; TABLE_A[EXEC_DATE] = "20/02/2019") and option 2 as FILTER(TABLE_A; TABLE_A[EXEC_DATE] = [dateSelected]). Quote from the post:
In option 1, in the filter function, you are iterating
over each row of your 'Table' (row context). In option 2, because you
are using a measure as part of the filter condition, this row context
is transformed into an equivalent filter context (context transition).
Using variables (...) is very convenient when you want to filter
a column based on the value of a measure but you don't want context
transition to apply.

How to select the last value of the day with DAX in Power BI

I am new to power BI and stuck with an issue. I have my model as follows:
Date Dimension
Measurement Fact
The date column in Date Dimension is link to measuredate in Measurement Fact
Below is a sample data:
NB: In edit query, I have changed the type of measuredate to Date only.
I have tried the measure below but it doesn't work the way I want. It will sum all the values of the day but what I want is the last value of the day:
day_fuel_consumption =
CALCULATE (
SUM ( measurement[measurementvalue] ),
FILTER (
measurement,
measurement[metername] = "C-FUEL"
&& measurement[measuredate] = MAX ( measurement[measuredate] )
)
)
My Goal is to get 29242, i.e the last value of the day. Remember that measuredate is a Date field and not Datetime (I changed to Date field so that my Year and Month filter can work correctly). I have changed the type in edit query.
Changing your measure to use a variable could be the solution:
DFC =
var maxDate = MAX(measurement[measuredate])
return
CALCULATE(
SUM(measurement[measurementvalue]),
measurement[measuredate] = maxDate
)
However, you should keep the datetime format for measureDate. If you don't want to see the time stamp just change the format I power bi. Otherwise power bi will see two values with max date and sum them, instead of taking the last one.
Well, if you want to avoid creating a measure, you could drag the fields you are filtering over to the visual filters pane. Click your visual, and scroll a tiny bit and you will see the section I am referring to. From there, just drag the field you are trying to filter In this case, your value. Then select "Top N". It will allow you to select a top (number) or bottom (number) based on another field. Strange enough, it does allow you to do top value by top value. It doesn't make sense when you say it out loud, but it works all the same.
This will show you the top values for whatever value field you are trying to use. As an added bonus, you can show how little or how many you want, on the fly.
As far as DAX goes, I'm afraid I am a little DAX illiterate compared to some other folks that may be able to help you.
I had to create two separate measures as shown below for this to work as I wanted:
max_measurement_id_cf = CALCULATE(MAX(measurement[measurementid]), FILTER(measurement, measurement[metername] = "C-FUEL"))
DFC =
var max_id_cf = [max_measurement_id_cf]
return
CALCULATE(SUM(measurement[measurementvalue]), measurement[measurementid] = max_id_cf)

Setting the Default Value of a Slicer on power bi

I want to set default filter of this week to slicer.However ,every answer use the option list.
if(weeknum(now())=weeknum([mydate]),"current week",[mydate]).
I selected the bar and choose start date with end date to filter date.On the previous way it's work on option-list but not on bar.
Any ideas?
I'd go about this in two ways.
Create a slicer which is used to calculate the week:
ThisWeek = if(weeknum(now) = weeknum(date), "Yes", "No")
It is however worth noting that if you have a data set that contains dates over several years it could show more data than required. In this case I would create the below column and use a Slicer based off of that.
ThisWeek = if(weeknum(now) = weeknum(date && year(now) = year(date), "Yes", "No")
You can then setup the interactions to filter your date slicer so the default range would be set as the value defined within "ThisWeek"
Alternately you could create a page filter which only shows records for this week. Again you would use the same format as above however there would be no need for the slicer.