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:
Related
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.
I have the following measure:
test = SWITCH(TRUE(),
MAX(test[month])>=9&&MAX(test[month])<=12,"fall",
MAX(test[month])>=1&&MAX(test[month])<=3,"winter",
MAX(test[month])>=4&&MAX(test[month])<=6,"spring",
MAX(test[month])>=7&&MAX(test[month])<=8,"summer")
Currently it looks at the month number (i.e. "3" for March and outputs "winter", what I'd like however is it to output is a count per season to show the distribution of the seasons in the dataset.
For example my desired output would be
Month Number
Count of occurrences of each season
fall
5
winter
7
spring
11
summer
2
I can't have a calculated column here either as I will want to make this measure dynamic later on with the use of a slicer, can someone tell me if this is possible?
The issue here is that you want to define your categories within the measure. Measures are not dynamic without some filter-context.
Take this for example:
Notice that the output of the calculation is identical between seasons.
There is no filter context to help the measure discern between the different seasons because these seasons are not defined in the model. (At least, I don't know how to make this work)
Switch returns the first true result. So, if you have values like in your sample, then start with the smallest, then bigger, and the largest at the end.
test =
SWITCH(
TRUE()
,MAX(test[month])<4,"winter" -- test <4
,MAX(test[month])<7,"spring" -- 3< test < 7
,MAX(test[month])<9,"summer" -- 6< test < 9 -- Is it ok that you have 2 months in
,"fall" -- 8< test -- summer and 4 in fall?
)
If you use MAX(test[month])<4,"winter" instead of MAX(test[month])<=3,"winter" then you avoid one calculation step and the code will be faster.
Then you need to use the result to find months numbers and get dates from the selected months. Then calculate your table filtered by months dates. If this answer is not enough to solve the case, then give more information about you table, it's columns, and what do you mean by 'Count of occurrences of each season', exactly what does 'occurrences' mean, is it a number of certain rows or some unique values.
My visual's x-axis is Date, aggregated by month, and the y-axis is total sales (sum of costs). For some months, I had no sales, but Quicksight ignores these and only shows me the months that do have data in them, even though I want the exact number of months that I specify in my time range parameter.
So, when I ask to show the last 12 months, Quicksight shows me only 4, since for the other 8 I don't have any records.
How can I make those months show as 0, instead of being excluded altogether?
---------- EDIT (possible solution) --------------
Since my analysis relied on selecting a specific product code and only getting the sums for that, I took off the filter, and instead used a calculated field of:
sumIf(sales, productCode = $productCodeParam$).
I imagine this approach works on really small datasets too if you want to use sumIf and list all of your categories there, but otherwise, by omitting data with filtering you have nothing to result in 0, since Quicksight doesn't evaluate sum(null + null) into 0.
I have issues with Data sorting
I have spend data by period which is a combination of year and month. For example if the period is March 2019 then period would show 201903. Data type of this period field is "Number". I have spend data starting from period 201501 to 201903.
Now I am creating a line chart to show spend trend with period in X axis and spend in Y axis. I have sorted (ascending) the chart by period, however sorting works ok partially, means period that I see in the chart are mentioned below:-
201708,201801,201806,201807,201808,201809,201810,201811,201812,201901,201902,201903
Not sure why sorting option is not working
Also in the Visual Level filter I want to show trailing 12 months spend, details of Visual Level filters that i selected are as follows:-
Visual Level Filter - Period
Filter Type - Top N
Show item - Bottom 12
By Value - Spend Amount
The expected result that I want in the line chart is :-
201804,201805,201806,201807,201808,201809,201810,201811,201812,201901,201902,201903
I checked the data and confirm it has all periods starting from 201501 to 201903
Any help would be highly appreciated
In Google Sheets, how can you use the IF statement using the output of a cell's formatted value?
I've created a Google Sheet with a date value in B1. The cell is formatted using the date format. B1 is then copied across to the right so that it increments the days of the month.
In B2, based on the B1 date, I want to display the day value (ie Thu, Fri, Sat etc.). Similarly to the first step, I set the date format under Format > Number > More formats > More date and time formats, then from the select box, choose the day and I want to display the "Tue" date format.
Then in B8, I want to display an amount of 30 every Thursday, otherwise, show 0.
This is where it doesn't work. Does it seem like the rendered cell's value can't be used in an IF statement? My desired output is that every the value in row 2 is a 'Thu' display 30.
As a side note, I jumped on Google support and asked this same question. Even though they are technical support, I thought I'd give them a try anyway, after all, I am paying for GSuite.
This is the formula they came back to me with: =if(B2=B1, "30", "0").
Of course, this formula will work in B8, because B2 is equal to B1 in the actual cell value, it doesn't take into account the formatted cell value. This formula will fail the output we need as it will always display 30 instead of only then row 2 is 'Thu'.
So essentially, is there a function in Google Sheets for a rendered cell value? Or another solution around this?
Note: I do NOT want to use any scripting to get this to work.
try it like this:
=IF(TEXT(B2, "ddd")="Thu", 30, 0)
Please try and copy across to suit:
=30*(WEEKDAY(B1)=5)
No IF, but shorter.