Power BI Column showing T/F - powerbi

I am looking to create a column in Power BI that will display a T/F only on the first instance of a [Patient_ID]. However, I also want to include a filter to only show the ones which have a [Visit_Status_Code] of CHK. I have attempted a few different iterations, and here is what I have so far. It is not excluding the other status codes, as I need it to.
New_Pt? =
COUNTROWS(
FILTER(
'Appointments',
Appointments[Patient_ID] = EARLIER(Appointments[Patient_ID]) &&
Appointments[Visit_Status_Code] = "CHK"
)
) =1
I would appreciate any help seeing where my errors are

Related

Power BI Min date of each category

I am familiar with SQL and I can write a query to return results of a query to Select MIN(Date), MAX(Date), SUM(quality) and GROUP BY. However, I am new to Power BI and DAX and find it difficult to do the same on Power BI. Below is my situation.
These tables on Power BI:
Dim_ManefactureDate
Dim_ReleaseDate
Fact_OrderID
Table Relationships
Adding a table visualization to a new page to show data from three tables above, data is showing as below:
Under Values of Visualizations, when selecting SUM over Netweight, it automatically summarizes expected Netweight. However, for ManufactureDate and ReleaseDate, when selecting Earliest then Power BI table shows unexpected 1/01/1900 values like this:
I expect earliest date of each OrderID as below:
I have also tried to use a DAX function to create a new column but it gets error
ManufactureDate_Earliest =
VAR Sum_Netweight = SUM(Fact_OrderID[NetWeight])
VAR GroupBy_OrderID = GROUPBY(Fact_OrderID,Fact_OrderID[OrderID])
RETURN
CALCULATE(
MIN(RELATED(Dim_ManufactureDate[DateBK]))
)
Thank you very much for your help
Due to getting values from relationship tables, used these measured and solved the issue
ManufactureDate_Earliest =
CALCULATE(
MIN(ManufactureDate[DateBK]),
CROSSFILTER(Fact_Order[ManufactureDate_DateSK], ManufactureDate[DateSK], BOTH)
)
ReleaseDate_Earliest =
CALCULATE(
MIN(ReleaseDate[DateBK]),
CROSSFILTER(Fact_Order[ReleaseDate_DateSK], ReleaseDate[DateSK], BOTH)
)

DAX filter column string values being shown in UI

I am displaying values from a specific column in a table, say TableP.
This column has some invalid data that I want to filter out.
Using a DAX measure,
Measure = IF ( 'TableP'[columnValue] <> "error#error.com", 'TableP'[columnValue] )
So with the above code, I am getting an error of
A single value cannot be determined.
So clearly wrong approach. Would appreciate some guidance on best practices :)
Is this the best way to solve this issue
The best option is to filter the records from your data source in data cleaning step in using Power Query editor. But if it is a requirement and you can not perform that, you can create your measure as below-
Measure =
CALCULATE(
SUM(TableP[your_measure_column]),
NOT (TableP[columnValue] IN{"error#error.com", "error2#error.com"})
)
Here is another option you can try your luck with-
Measure =
CALCULATE(
SUM(TableP[your_measure_column]),
FILTER(
TableP,
NOT(TableP[columnValue] IN{"error#error.com", "error2#error.com"})
)
)
And.... another option :)
Measure =
CALCULATE(
SUM(TableP[your_measure_column]),
NOT CONTAINSROW(
{"error#error.com", "error2#error.com"},
TableP[columnValue]
)
)

How to Show last period (Fiscal Year) of sale, based on multi-filters report

I tried create a dashboard based on fiscal year, with more Filters, like region, sales rep name, ...
Example files avaliable on dropbox:
https://www.dropbox.com/sh/l25kdz6enmg35yb/AABPuOk3kKOpfQdKDfRUcnX2a?dl=0
On my closest attempt, i tried this follow:
Add one column on my data set, naming each period as distinct number, like: "17";"18";"19", due to deslocated fiscal year (april to march).
Then create a measure:
PREVIOUS CROP_YEAR = SWITCH(TRUE();
SELECTEDVALUE('dataset'[Crop-X])=16;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
SELECTEDVALUE('dataset'[Crop-X])=17;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
SELECTEDVALUE('dataset'[Crop-X])=18;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
SELECTEDVALUE('dataset'[Crop-X])=19;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
0)
Expected output was:
Values based on all filters applied, But instead i just get an empty charts
The measure is return the total because you are explicitly asking for it by using the ALL function. This removes all the filters from the dataset thus returning a grand total. This can work but it creates a complexity in your dataset with respect of having two time dimensions. The way to solve this is to first make sure you filter the date correctly with respect to both dimensions
PREVIOUS YEAR =
CALCULATE(
SUM('dataset'[Order Value]);
FILTER(
ALL ( 'dataset' ) ;
AND (
'dataset'[Crop-X] = MAX('dataset'[Crop-X]) -1 ;
'dataset'[YEAR] = MAX('dataset'[YEAR] ) -1
)
)
)
Furthermore, this measure still uses the ALL function which means any other filters get ignored. Using ALLSELECTED instead would result in the relative time filtering to result in nothing as soon as you select any time based slicer in your dashboard, this prevents the filter from looking at any other part of the dataset that is not within the primary sliced dataset. The workaround would be to use ALLEXCEPT and add the filters you want to be able to use as arguments. Downside is that any filter you add to your dashboard will have to be added to the exception manually.
PREVIOUS YEAR =
CALCULATE(
SUM('dataset'[Order Value]);
FILTER(
ALLEXCEPT( 'dataset' ; Dim1[Group] ; Dim1[Manager] ; Dim1[Region] ) ;
AND (
'dataset'[Crop-X] = MAX('dataset'[Crop-X]) -1 ;
'dataset'[YEAR] = MAX('dataset'[YEAR] ) -1
)
)
)

Calculate Previousmonth does not work with Slicer in PowerBI

My question might be simple but I've been stuck here for a while.
I'm trying to get the values for current month and previous month. I created 2 Measures to do that (CurrentVal and PreviousVal).
My DAX measures are:
CurrentVal = SUM ( Database[KPI_Value] )
PreviousVal =
CALCULATE (
[CurrentVal];
PREVIOUSMONTH ( DIM_Date[Date] )
)
In the image below, when displayed as a table, you can see it's working fine.
However, I don't want a table like that, but instead I want a slicer where the user can select the month and he will be able to see the current and previous month values, just like the image below.
The problem, as you can see, is that when I remove the Date from the table and include the slicer, the PreviousVal returns always blank (in this example, it should return 0,44). What am I doing wrong here?
Thanks in advance!
What you have set up will work, assuming:
You have a relationship between the Date fields in the Database and DIM_Date tables
Table DIM_Date is marked as a date table (Table view, Modelling tab, Mark as Date Table )
Here's a worked example: https://excel.solutions/so20181121_previousmonth/

Get preview rowvalue filtered by ID

I've been struggling with DAX while creating a model to publish on Power BI and the actual problem is presented on the image here. Basically I need a column that shows the value from the predecessor time for the same id.
I did with ranking but wanted to know if it is possible to make it better.
How would you guys do it?
Rank = COUNTROWS(FILTER(test; [id] = EARLIER([id]) && [Date] <= EARLIER([Date])))
Past = if(test[Rank]=1;0; LOOKUPVALUE(test[qt];teste[Rank];test[Rank]-1;test[id];test[id]))
This is a solution tested with the basic model you posted, I don't guarantee this is a machine low cost expression but you can give it a try.
I've created a column called PREVIOUS in which is calculated the previous qty for every row based on the date for the same id.
PREVIOUS =
CALCULATE (
MAX ( TableName[qt] ),
FILTER (
TableName,
EARLIER ( TableName[id] ) = TableName[id]
&& EARLIER ( TableName[date] ) > TableName[date]
)
)
The following is a Power BI table using the PREVIOUS column.
Let me know if this helps.