Power BI: Format integer to string (conditional formatting) - powerbi

Power Bi is getting data from MySQL from the table Vehicle Supports. In the website there is an enum of 1 = Yes and 0 = No.
I have a Donut chart which is displaying the integers since the data being saved in DB are integers.
I can't use conditional formatting as some tutorials mention since this is not a table. I also tried FORMAT() and didn't work.
How can I format the integers? If the number is 1 then change it to "Yes" and if the number is 0 then change it to No.

https://learn.microsoft.com/en-us/dax/if-function-dax
String = IF(number=1,"Yes","No")

Related

Power BI Add rank or row number to column

Im trying to add just a simple rank numbering or row number to column but no luck.
I have a simple test table which consist of 2 columns - Name and Room number. I have attached Room Number to filter so it can be filtered. My goal is to add a number to resulted raws. Im using dax measure for this but no luck. This is my DAX measure code:
Visitor num = RANKX('myTab',CALCULATE(count('myTab'[Name])))
But it returns only 1 for each row
My PBIX file
Try changing the filter context:
Visitor num = RANKX(ALLSELECTED('myTab'),CALCULATE(MAX('myTab'[Name])))

In PowerBI what options are there to hide/redact/mask values in visuals to anonymise data

What options are there in PowerBI to suppress, redact or hide values to anonymise values in reports and visuals without loosing detail and have that restriction apply to multiple pages in a report?
Cat
Count
%
Category 1
23
10
Category 2
2
0.9%
Category 3
4
1.7%
So that its possible to keep the rows but end up with a placeholder where count is <4 and % is greater than 1% but less than 2%
Cat
Count
%
Category 1
23
10
Category 2
*
0.9%
Category 3
4
*
So far my experience has been
a measure with a filter applied will hide rows but you can't apply a measure filter to an entire page or all report pages.
Ive seen mention of conditional formatting to hide the value by having the font and background the same colour but that seems open to error and labour intensive.
I also want to be clear when a value has been suppressed or masked
I suspect there is a more better way but I haven't been able to figure out where to even start.
OK, I have something working but you will need Tabular Editor to create a calculation group. Here are the steps.
I'm using the following table (named "Table") as the source data.
Add two measures (calculation groups only work on measures) as follows.
% Measure = SUM('Table'[%])
Count Measure = SUM('Table'[Count ])
Open tabular editor and create a new calculation group named "CG" with a calculation item named "Mask". Paste the following code into the calculation item.
if (
(selectedmeasurename() = "% Measure" && selectedmeasure() >1 && selectedmeasure() <2)
||
(selectedmeasurename() = "Count Measure" && selectedmeasure() <4)
,"*",selectedmeasure()
)
4. Save the calculation group and in Power BI drag the name column onto the filter for all pages as follows, ensuring it is selected:
The masking will now happen across all reports automatically. Below you can see the same table on two different reports which have now been successfully masked.
It depends on your data connection type as to whether this is available, but a calculated column (instead of a measure) can be used as a filter at the "this page" or "all pages" level.
If this option is available, then you can find it right next to the "New Measure" field.
Using this and your sample data above, I created a couple of calculated columns and show the resulting table. You can then display these columns and use them as filters throughout the report. Your DAX may be slightly different depending on how the actual data is formatted and such.
Count Calculated Column
Masked Count =
IF(
'Table'[Count] < 4,
"*",
CONVERT('Table'[Count], STRING)
)
% Calculated Column
Masked % =
IF(
'Table'[%] > .01 && 'Table'[%] < .02,
"*",
CONVERT('Table'[%] * 100, STRING) & "%"
)
Resulting Table
Example of how the filter can be used
The values of these columns will update as your data source is refreshed in Power BI. However, calculated columns aren't available for Live Connection, in which case you would have to do this kind of logic at a lower level (in Analysis Services for example).
Additionally, you could potentially use Power Query Editor to accomplish this kind of thing.

Power BI multiple lines on the y-axis

Explanation of the dataset I am using
I have a dataset containing the following values:
Timestamp
Value
Tag
The combination of a timestamp and a tag makes a row unique.
This dataset could, for example, make it possible to retrieve the value of tag A-A-A at 2019-05-20 00:00:00
Goal visualization (in Power BI)
The following image shows the visualization I would like to make in Power BI.
X-axis = Timestamp
Y1-axis = Value of Tag A-A-A
Y2-axis = Value of Tag B-B-B
Y3-axis = Value of tag C-C-C
Problem
I am unable to make a graph in Power BI that shows the Value of each Tag at a certain Timestamp.
I am curious how I can make Power BI understand that a Value corresponds to two values (Tag + Timestamp)
You should be able to achieve this by putting the Tag column in the Legend box as shown here:

Vintage Chart in Power BI

I'm trying to display a vintage analysis line chart in Power BI. I have replicated the chart in Excel from an output of an SQL query.
Each month 0,1,..,12 is the month relative from the business date row representing +1 months from , +2 Months from ... etc.
The issue I'm having is that this dataset doesn't work in Power BI. What does the base data have to look like in order to achieve the line chart as seen in the picture?
The data I have in Power Bi is structured thusly:
[orig] | [0] | 1 | 2 | ... | [12] | [Date]
where orig .. [12] are aggregate columns (counts) for each Date in a cumulative fashion. i.e [n] = Cts + [n-1]. This data is prepared in SQL. Power Bi does no aggregation.
Each date is supposed to be it's own line from 1 - twelve (x axis) with the values being the cumulative totals as described above.
I have made some progress on the chart... looks to be good. except it's backwards...
I have tried creating a sorting column, but get the error message that
FIXED IT!!!!! simple solution. sort ascending on the chart.
But, now, how do I stop PowerBI from displaying a flat line? Below is an example using EXCEL of what the chart should like.
In Power BI the series need to be in columns, so you need to transpose the table and make the dates the column headings. Add a column for the months numbers as text, not numbers, so it can go on the axis.
Try using three columns. One for the date, one for the Category (0,1,2,etc.), and one for the percentage. You can accomplish this by using unpivot in the Power Query window.

Using WHERE in PROC SQL Error

Currently I'm trying to filter the output I have to display only products which have discounts greater than or equal to 60%. The variable discount lists all their values in the format such as 50%, 60% etc.
PROC SQL;
SELECT discount.Product_ID,Product_Name,Start_Date,End_Date,Discount
FROM Final.discount AS d, Final.product_dim AS p
WHERE d.Product_ID=p.Product_ID
AND Discount >= 60%;
QUIT;
I dont know why this isn't working, but the error from the log tells me that the percent sign isnt recognized? How would I fix this to get the output I desire?
Assuming the variable is numeric with the PERCENTw.d format applied (so likely PERCENT5. given your display), you would write it like so:
Discount >= 0.6;
The PERCENTw.d format displays numbers between 0 and 1 as 0% - 100%.
If your variable is character, then you would probably need to convert it to a number first (as '100%' > '60%' is false).
input(Discount, PERCENT5.) >= 0.6
This is well covered in Rick Wicklin's blog post on the Do Loop.