I am facing very weird situation while using the DAX format function.
If I remove the format function it is working, If I add the format function it returns all the customer record even after applying the page level filter for specific customer.
When I comment FORMAT(hourNum,"#00")&":"&FORMAT(minuteNum,"#00") and Uncomment minuteNum . All the things work well.
I have also tried to replace format with concatenate function and it is still the same.
Can anyone please suggest what needs to be done here.
Output of the code is - 01:20
DAX Query
AverageX6IntervalLabel** =
VAR hourNum=INT(divide([Average],60))
VAR minuteNum=MOD([Average],60)
RETURN
--minuteNum
FORMAT(hourNum,"#00")&":"&FORMAT(minuteNum,"#00")
Added the picture of the actual DAX which is causing the issue, If I comment line 10 and Uncomment line 8 everything is working as expected, even line 9 also work.
I expect this behavior will be explained by the difference between BLANK() and the empty string.
What is most likely happening is that you are getting fowled up by the behavior where a visual will filter out blanks by default, but an empty string will be shown. This is an annoying subtlety, because the format function will return an empty string even when its input is a blank.
FORMAT(BLANK(),"") <> BLANK()
To fix this oddity, you will want to need to add a little code to try to help reinforce that blanks should stay blanks.
AverageX6IntervalLabel** =
VAR hourNum=INT(divide([Average],60))
VAR minuteNum=MOD([Average],60)
VAR result = FORMAT(hourNum,"#00")&":"&FORMAT(minuteNum,"#00")
RETURN
IF (result = ":", BLANK(), result)
Hope it helps.
Related
I have a table similar to the one attached below:
What I would like to do, using power query, is conditionally filter out (remove) rows where CenterNum = 1101 and DepCode = 257. I figured Table.SelectRows() would work but it doesn't and the query just returns, this table is empty. The #"Expanded AccountLookup" ,in my formula below, is referencing the power query applied step before the one I am trying to create. I'm hoping to get some input on how to remove rows based on these two paramters.
= Table.SelectRows(#"Expanded AccountLookup", each [CostCenterNumber] = "1111001" and [NoteTypeCode] = "257")
Thank you!
You didn’t post a screenshot so it is hard to tell if the column format is text or numerical but try removing the quotes around the numbers
= Table.SelectRows(#"Expanded AccountLookup", each [CostCenterNumber] = 1111001 and [NoteTypeCode] = 257)
If that doesn't work, check the actual column names against what you are using, especially for case (upper/lower) and leading/trailing spaces. The best way to do that is to temporarily rename it, and look at the code for the "from name"
I'm getting an unexpected result when I use an IF in the RETURN clause of a DAX expression. If I don't use the IF, but instead just a variable, then the result is ok.
I've created a test scenario to explain my problem:
I have two test tables:
Table: "Test Object"
Table: "Test Group"
These have a unidirectional relation on "Group code"
I have created a measure "Test measure":
This gives the correct result:
I have set a page filter to only show Group Code "G01".
This all works ok up to this point.
But it goes wrong when I use an IF function:
I then get the following (incorrect) result. Apparently the relation and/or page filter seems to be ignored now:
NB: The result is the same regardless of from which table I use the "Group code" field.
What am I missing here?
I've created a PBIX file that shows the problem:
https://www.dropbox.com/s/76ld1kv503ul6nm/DAX%20problem%20with%20IF.pbix?dl=0
This is called "Auto-Exist" in PBI:
https://www.sqlbi.com/articles/understanding-dax-auto-exist/
If you look closer to the results, you'll notice that your report shows all possible combinations between Group Codes and Object Codes.
This is happening whenever you use a combination of fields from the different tables in a report: PBI first creates a cross-join between these fields, and then eliminates those combinations that result in blanks, so you only see meaningful combinations.
However, you IF statement overrides this logic - you are returning a result always, even if a combination is blank (Blank < 40 test returns "low end" because blank is treated as zero).
To fix it, calculate results only if the variable is not blank, i.e:
Price category =
var lowestPrice = MIN(Object[Price])
var result = IF( NOT ISBLANK(lowestPrice), IF(lowestPrice < 40, "Low end", "High end"))
Return result
You will get:
P.S. Page filter is irrelevant here, it simply filters the table after it's calculated.
I need to develop a report with a table that includes several dimensions and displays a sales revenue measure. Most of the times this measure throws a zero, but the user wants to visualize a blank space instead. I have searched around, but I couldn´t find anything that gives me support. So if anyone has experimented this or found a workaround I would thank you for your time.
You could use a IF condition to replace 0 with blanks. For example, if you are summarizing a field called "Sales" the following formula would work:
Measure = IF(Sum(Sales)=0,"",Sum(Sales))
Hope this helps.
Adding the additional option based on Ricardo's suggestion:
Measure = IF(Sum(Sales)=0,Blank(),Sum(Sales))
If you have a measure [Measure] and you want to replace 0 with a blank, you can do the following:
MeasureReplaceBlank =
VAR Measure = [Measure]
RETURN IF ( Measure = 0, BLANK(), Measure )
Note that since I stored the calculation of [Measure] as a variable, I don't need to call it twice (once for the condition and once for the True branch of the IF function).
I had a problem with my code. It returns the below error:
DAX comparison operates do not support comparing values of type date with values of type text.
Basically, I want to count rows based on some conditions. And I know there is a need to convert the data type, but I am not sure how to do it.
Total Open Issues =
--------------------
--basic info
VAR SELECTEDDATE =
DATEVALUE(SELECTEDVALUE(Calender[FullDateAlternateKey].[Date]))
--------------------
--FIND the relvent data
VAR rlvttable =
calculatetable(
Tracker,
Tracker[Catagory]="ISSUE",
DATEVALUE(Tracker[ClosedDate])>SELECTEDDATE
||Tracker[ClosedDate]=""
)
--------------------
--Results
Return
countrows(rlvttable)
Anyone could advise me how to correct it? Thanks~
Check the data type of columns Tracker[ClosedDate] and Calender[FullDateAlternateKey] - one of them is Text, rather than Date.
To fix, you could:
choose a different field which is already a Date format
change the format of the offending column
use DATEVALUE in your measure, to convert the text date to a real date.
It also looks like you need to edit this statement, as these conditions conflict:
Tracker[ClosedDate]>SELECTEDDATE
&&Tracker[ClosedDate]=""
I am trying to compare the closedDate with "". I should use blank() instead.
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: