Conditional Formatting in Power BI - powerbi

I have created a matrix and a table on the same tab of a Power BI Report. (See 1st picture below)
enter image description here
The table on the left uses conditional columns which I manually inserted into the table. (For example: If the time is 8:00 AM, then 15 staff is then 49, and so on and so fourth). Both visuals are useing the same times. The values in the matrix are using a column called StudentID, and the values are as Count (Distinct).
I was asked to find a way to color the values on the right as follows:
If the Value is above the 5 Staff number, then color it Green
If the Value is below the 15 Staff number, then color it Red
Ex: On January 25, 2022 the value is 30. This value would be Red
If Value is in between, then color is Yellow
Here is an example of the data I am using
Time Date StudentID StudentName College CreditHours 15 Staff 5 Staff
I am not really 100% sure how this would be able to get formatted the way I am being asked. Would this be using Variables in a calculation? I struggle so much with variables and some DAX Functions. I've tried to do drop down on the values and conditionally format, however that really didn't work for my case.

Related

How can I display months without no data?

I follow the following blog http://sqljason.com/2018/03/display-last-n-months-selected-month-using-single-date-dimension-in-powe... in order to display Display Last N Months & Selected Month using Single Date Dimension in Power BI.
I've an issue when trying to display month-year when there is no data in the fact table sales.
I did modification: https://1drv.ms/u/s!Amd7BXzYs7AVg3xJ1MKPYI_PIw3z
How to show to show for example October, november and december 2015 as an example?
I downloaded your PBIX file and looked through it.
I am unsure what you exactly want to see, because your report has a few quirks in it.
I'll try to sum them up:
You have a 'select month' drop down menu ánd a slider for selecting the number of months (As 'sales for last x months). This doesn't work. Since you now need to manually select the wanted months in the drop down menu with CTRL+Click (On each month) ánd you need to use the slider.
Next to that, your calculations seem to be wrong. If I only select Dec-16 I get 70. If I select Nov-16 and Dec-16, the sales in Dec-16 suddenly become 70 and Nov-16 takes over. If I select until July-16, July-16 gets 70 and Dec-16 gets 120.. I don't know if this is how you want it but it looks like strange behaviour.
A good tip for measures. If you sum, divide or do any calculation. End with +0. That way you wont see (Blank) but 0. E.g.
Sales (Selected Month) = SUM(Sales[Sales]) + 0
Also, you have made a small date table, which is good. But you don't use this consistently through your report. For selecting months you use the date table and for the graph you use the date in the sales table. It is better to use the date table for dates, since that is it's sole purpose.

PowerBI measure calculates average incorrectly - why?

To preface this, I'm fairly experienced in Excel and VBA but new to PowerBI and more than a bit confused.
I have a flat table with a [creationdate]-, [Prio] (Priority (1,2,3)) and a calculated [Days Open] column, among many irrelevant others. I need to create a chart that displays the average days a case was open by priority of the case.
To display the average "days required" per (opening-) month for the past 18 months, I created the following measure:
Prio 1 = CALCULATE(AVERAGE('SourceName'[Days Open]),'SourceName'[Prio]=1)
Then I used that as a value, and used the [creationdate] as the x-axis. (Later I changed the x-axis to a new date table linked to [creationdate] without it making a difference.) To display this as monthly averages, I used the hierarchy limited to years and months, and went down one level in the chart.
Something seemed off so I checked first in Excel, then in the data source in PowerBI and yep: The averages in the PowerBI chart are complete bullshit.
Where did I go wrong? I assume it has something to do with the date hierarchy... So I created a date table as recommended (which....why?!) and linked it. That didn't make a difference.
Meanwhile in the data panel if I filter by the date column and calculate the average with the filtered selection of numbers externally, everything works as expected, so its not like there's a date formatting issue.
Do I have to create a calculated column with something akin to
DATE(YEAR([DateColumn]),MONTH([DateColumn]),1)
, then use that as the x-axis without the hierarchy, and hope nobody cares about the day in the label? Or is there something wrong with the measure used? I'm completely lost.

PowerBI - Conditionally format a date column relative to todays date

I have a report, updated on a daily basis, that provides me with a list of remote devices connected to our server.
A date column tells me the last date (and time) that a remote device sent data.
I want to conditionally format the column so that, if the last date is:
Today's date: the cell is green
Yesterday's date: the cell is yellow
Up to 30 days old: the cell is orange
older than 30 days: the cell is red
empty: the cell is empty
I've had a small degree of success in progressing towards my goal, but the colours are the wrong way round and I'm struggling with the "if" syntax. I can get today's date displaying yellow and every other date displaying green - but, to be honest, I've no idea quite how !!
Last data seen
This is what I've done so far...
I have created a measure "flag3" as below (with the intention of showing green for today, orange 1 day old and red for 2 days old)
flag3 = if(DATEDIFF(TODAY(),SELECTEDVALUE(DeviceStatus[Column1.lastDataRecordTime]),DAY),1,
(if(DATEDIFF(TODAY()-1,SELECTEDVALUE(DeviceStatus[Column1.lastDataRecordTime]),DAY),2,
(if(DATEDIFF(TODAY()-2,SELECTEDVALUE(DeviceStatus[Column1.lastDataRecordTime]),DAY),3)))))
And I have created conditional formatting based on background colour,
formatted by rules,
based on field flag3
If the value is 1 - then green
If it's 2 - then orange
If it's 3 - then red
Conditional Formatting based on Background Colour
As I've said previously- it's sort of working but the colours are the wrong way round and I'm struggling with syntax.
You can simply use a DATEDIFF formula - DATEDIFF(TODAY(),FIRSTDATE('Table_Name'[Date_Column),DAY) without an if function and use it in conditional formatting with following conditions:
greater than -10000 and less than -30
greater than -30 and less than
-1 euqal to -1
equal to 0
greater than 0 and less than 10000
Note: Make sure to replace Table_Name and Date_Column with your respective information
Example screenshot below:

How to deal with missing dates in Power BI line charts? (Tabular SSAS)

In SSAS Tabular mode, we have different tables with slowly changing dimensions (SCD Type 2). In Power BI, we now want to show for example the price history for one object over time. I want to display that with a Line Chart.
For the sample data, I added a Line Chart and activated the "Stepped" property in "Shapes", to have a clear cut of the price change. But unfortunately, Power BI displays the price change on Oct 5th (because this is the middle date between 3th and 7th) instead of Oct 7th. I know, that I would be able to solve it on database view layer, but I don't want to create so much data records for all different tables.
PRICE TABLE
**************************************
Price Valid from Valid To
**************************************
3'674 02.10.2019 02.10.2019
3'674 03.10.2019 06.10.2019
11'095 07.10.2019 07.10.2019
11'095 08.10.2019 01.01.2999
**************************************
Is there any way to prevent this behavior in the Power BI visualization or can I somehow calculate the missing dates in DAX?
I would have use date field from date dimension which has all the continuous date, then you may change your axis type for date continuous and it will generate smooth transition.

How can I get the number of days by month from a slicer in Power BI?

I just want to select a range of days in a slicer and show in a table the number of days for each month/period (month-year).
I used DAX to create a table with the information I need and I don't have problems with the periods (first column), it changes dinamically, the problem is the column "Days" (second column) because it's always showing the total number of days for each month.
Here my DAX code
SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))
Here the result
What I expect is:
2 for april, 31 for may, 1 for june
This is an issue with execution order.
SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))
Generates a calculated table. These are calculated when the data model is refreshed and stored in it. They are not refreshed each time a connected dimension is changed within a dashboard.
In your case, while changing date filters may hide rows from this table the number of days remains fixed at the number calculated initially when there was no filter context on the data i.e. counting all days in the month.
If you want the result to change then you need to use a measure instead of a calculated table. Measures react to the current filter context within the report and so will adjust their output each time a slicer is changed.
The needed measure will depend on your model but might be something as simple as:
CountOfDays := CountRows(DimDate)