Clustered Bar Chart to show % Complete based on Filters - powerbi

I think I have just been staring at this for too long and have worked myself into a corner.
So let's say I have the following data:
I have locations that get monthly utility usage numbers. I want to create a clustered bar chart that shows how many months have data.
The "Merge_Use" column can have numbers, blanks, and N/A. Any number > 0 OR N/A is considered complete. 0 or blank is incomplete.
I want a clustered bar chart that shows % complete, and is split by quarter and metric type, that shows the global total % complete, but can be filtered to show the % complete by region or individual location (relationships for TRT_ID to region is housed in a separate table). For some reason I can't wrap my mind around the measure that would do that.
This was my first try. I used a calculated column, but it wasn't until after I got to the visual stage that I realized that my calculated column is static and won't be affected by filtering. (It sounds silly now but I made a column that assigned each completed field a % out of the total fields, i.e. 1/total # rows, thinking I could just sum these together in the visual).
How would you do this?

I may have solved my own problem.
I added a conditional column with Yes/No for "completed" based off my criteria. (i.e. if "" then "No", else "Yes")
Then added the following measure:
% YES =
DIVIDE (
CALCULATE ( COUNT ( Leadership_Usage_Tracking_v2[Completed] ), Leadership_Usage_Tracking_v2[Completed] = "YES" ),
CALCULATE ( COUNT ( Leadership_Usage_Tracking_v2[Completed] ), ALLSELECTED ( Leadership_Usage_Tracking_v2[Completed] ) )
)
Seems to be working so far!

Related

Closing Stock Value

I am working on Powerbi. I need to calculate the closing stock value.
Here i am attaching the image link.
https://www.mediafire.com/file/wnxq5hh91jrwp2y/cgs.JPG/file
As i use the below formula in Closing Stock Measure
Closing Stock =
CALCULATE (
[Movement],
FILTER (
ALLEXCEPT ( mak_stockInHandValue, mak_stockInHandValue[GName],mak_stockInHandValue[ItCode] ),
mak_stockInHandValue[TransactDatee] <= MAX ( mak_stockInHandValue[TransactDatee] )
)
)
It is showing me the correct result on stock but when i am using the same formula in closing stock value measurement it is not giving me correct result.
if you can see in 2017 closing value should be 24673942+166903972-171299624 =20,278,290
I am also attaching the file in url of media fire
https://www.mediafire.com/file/wntdtu9pa04qnub/cgs_new.pbix/file
Please any one help in this
For Further Info
Closing stock Value = Closing Stock Value previous + initemvalue - outitemvalue
This is general term to get the Closing Stock
It's happening because in your calculations you use Avg Func which varies depending on the selection you make. See image below:
In 2016 the value per item is 28,426.20, but when you calculate Movement Value by applying a filter on the dates, the value per item is 27,094.46 which will affect the numbers that you used for previous period.
I've had a look in your model and you seem to have two columns with Price, I guess you need to use them to determine the out value, something like this:
OutItemvaluee =
IF(mak_stockInHandValue[OutQty] > 0,
mak_stockInHandValue[Price] + mak_stockInHandValue[pricen],
0)
And then change your outitemvalue formula to be:
outitemvalue = SUM(mak_stockInHandValue[OutItemvaluee])
edit: I had a look at your model, please see updated answer.

In the Films table create a calculated column called NumberBreaks which shows for each film the number of breaks needed

The Films table looks like this
There is a ComfortBreaks table looking like image
In the Films table I need to create a calculated column called NumberBreaks which shows for each film the number of breaks needed. To do this I have to pick out the value of the Breaks column where:
The value of the lower limit in the ComfortBreaks table is less than or equal to this film's running time in minutes
and
The value of the upper limit in the ComfortBreaks table is greater than this film's running time in minutes.
the result should look like the image below
There cannot be a relationship between the two tables. so this has to be done without creating relationship between them.
I tried lookup function but it showed error:A table of multiple values was supplied where a single value was expected.
You can use this below code for your custom column. Considering
number_of_breaks =
VAR current_row_run_time_minutes = Films[RunTimeMinutes]
RETURN
MINX (
FILTER(
ComfortBreaks,
ComfortBreaks[LowerLimit] <= current_row_run_time_minutes
&& ComfortBreaks[UperLimit] > MonthNumber
),
ComfortBreaks[Breaks]
)
You can perform your further average calculation on the new custom column now.

Display a blank instead of a 0 on a table on Power BI

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).

PowerBI DAX - Identifying first instance based on multiple criteria

Using DAX to identify first instance of a record
I'm faced with trying to identify the first instance in a database where someone (identified by the ID column) has purchased a product for the first time. It's possible for said person to purchase the product multiple times on different days, or purchase different products on the same day. I drummed up an excel formula that gets me there, but am having trouble translating into DAX.
=COUNTIFS(ID,ID,PurchaseDate,"<="&PurchaseDate,Product,Product)
Which results in the correct values in the "First Instance?" Column.
Ideally I won't have to hardcode values, as I would like to use the "Product" column as a parameter in the future. If there are other suggests aside from translating this in DAX, that would also be appreciated! (IE using filters, or other tools in PowerBI)
Thanks in advance!
This is very similar to an answer I gave to another question (which you can find here).
In that question, the request was to see a running count of rows for the given row's criteria (product, year, etc.). We can modify that slightly to get it to work in your problem.
This is the formula I provided in the answer I linked above. The basic concept is to use the EARLIER functions to get the value from the row and pass it into the filter statement.
Running Count =
COUNTROWS(
FILTER(
'Data',
[ProductName] = EARLIER([ProductName]) &&
[Customer] = EARLIER([Customer]) &&
[Seller] = EARLIER([Seller]) &&
[Year] <= EARLIER([Year])
)
)
What I would suggest for your problem is to create this as a TRUE/FALSE flag by simply checking if the running count is 1. This formula will evaluate to a Boolean flag.
First Instance =
COUNTROWS(
FILTER(
'Data',
[ID] = EARLIER([ID]) &&
[Product] = EARLIER([Product]) &&
[Purchase Date] <= EARLIER([Purchase Date])
)
) = 1

Calculate value if outside time range

I have a problem where I need to figure out if a project has values outside it's start and finish date range.
Below is a simple relationship of dimension table containing start and finish dates of the projects. And a fact table containing time registration.
The table below has a column 'Outside Date Range' Which I'd like to have a true/false value. for example if Main2 Table contains a date Monday, May 13, 2018. The column should show false.
I tried something like
Outside Date Range = CALCULATE(SUM(Main2[Value]), FILTER(Main2, Main2[Time] < LOOKUPVALUE(Main[Start], Main[Project], ALL(Main2[Project]))))
But not really sure how to approach the relationship between the two tables properly.
The two approaches I would suggest are either a calculated column or a measure.
Calculated column:
Outside Date Range =
VAR rowsOutsideRange =
CALCULATE (
COUNTROWS ( Main2 ),
FILTER (
RELATEDTABLE ( Main2 ),
Main2[Time] < Main[Start]
|| Main2[Time] > Main[Finish]
)
)
RETURN
IF ( rowsOutsideRange > 0, TRUE (), FALSE () )
You were pretty close in your solution! Since you have a relationship between the two tables RELATEDTABLE will only return the related rows which removes the necessity of a LOOKUPVALUE(). Also, counting the rows is sufficient since we only want to know if any rows exist outside of the range, not how many.
You could also create a measure:
Outside Date Range Measure :=
VAR rowsOutsideRange =
CALCULATE (
COUNTROWS ( Main2 ),
FILTER (
Main2,
Main2[Time] < MIN ( Main[Start] )
|| Main2[Time] > MAX ( Main[Finish] )
)
)
RETURN
IF ( rowsOutsideRange > 0, TRUE (), FALSE () )
Which is pretty similar to the calculated column, the only this is we need to aggregate the start and finish dates. On its own this measure doesn't have any value, it needs to be sliced by a project to be correct. If you would really want to you could use a SUMX() type of construction to create an overall TRUE/FALSE statement which tells you if any of the project have rows outside their ranges but for your use case I don't see the benefit of that.
The choice between a calculated column and a measure is dependent on the legibility of the code and resource usage. A calculated measure uses more memory and a measure uses more CPU.
Looking at your case I would go for a calculated column, which seems the most simple and clear solution.
Hope that helps!
Jan