Summation of rows based on Dropdown selection in Power BI - powerbi

I have a dropdown in Power BI that contains different project name such as Project One, Two, Three. I have included one formula to bring forecast value which is:
Forecast = Chase * Target%
I have created one measure that calculates forecast. The dataset contains weekly based data for Chase and Target %. For example week 1 (Jan 01-Jan 08) Chase will be 30 and target % as 10 hence the forecast for Week 1 is 3 (30*10%)
When I select one project from dropdown list e.g. "Project One" I see the forecast value populating correctly. Same goes if I select only one project from dropdown list .
The issue arises when I select multiple projects and then the forecast value brings the maximum value instead of bringing summation to the values of all weeks of all projects.
Question: What exactly is causing the issue?

Now I understand your requirement from your comments. You can achieve this through 2 step as explained below-
Step-1: Create a custom column in your data source as below-
row_level_forecast = finetarget[chase]/100.00 * finetarget[target]
Step-2: Create the final Measure as below-
forecast = sum(finetarget[row_level_forecast])
Now, use measure "forecast" in the report. This should give you the desired output.
ISSUE-2: From your comments
If I understand correct, you are talking about a case where you are concern about values in columns I marked red in the below picture-
If I am correct with my understanding, you wants to fill week-3 values for Project-1 with 80/70 and for Project-2 100/90. If this is ok, just follow these following steps.
Step-1: Go to EDIT mode clicking "Transform Data" option and select the table you wants to adjust data.
Step-2: Sort your data first for project_name (ascending) then week (ascending). The output will be also as shown in the above image.
Step-3: Select column "chase" in the table and click Fill>>Down option.
Step-4: Repeat step 3 for column"target" as well.
The final output should be as below. Just move back to main report by clicking "Close and Apply". Data should be now as expected in your report.

When you display the forecast, put it in a grid and add the project column, the week column (e.g. Week 1) and the forecast measure. When you select your multiple projects the grid will show each of those along with the calculated measure. If this does not work, there is something wrong with your measure and you should add your measure calculation script to your question.
The measure should be simple, something like:
Forecast = SUM(YourTable[Chase]) * AVERAGE(YourTable[Target%])

Related

In Power BI, how can I create a column that changes based on a slicer and visualization?

I'm pretty new to Power BI. I'm unsure how to approach this.
I have one visualization that displays the ten most frequently bought products in a time frame that is set by a slicer. In another visualization, I display how those products have been selling over the past few years (this time frame is not determined by the slicer). I want to display only the ten products that come from the first visualization, not the ten most common over the time frame in the second visualization.
How can I accomplish this? The approach I have in mind (and I'm open to others) is to create a true/false column that changes with the first visualization. "True" would be for products that are frequently bought as determined by the first visualization in the slicer-determined time range, and the second visualization would only look at values with a "true" in that column. How can I create a column (or table, maybe?) that changes depending on a visualization?
Clarification: most of the pages will say Top10 ... Actually, the measure used was a simple Top5 that includes products with the same number of orders than the 5th product. Therefore, to avoid dealing with larger images, 7 products will be seen but it is a Top5 ranking. The idea is you can replace it with your custom TopN measure.
What I understood:
The simplification of your model plus the disconnected help table would be:
I have one visualization that displays the ten most frequently bought
products in a time frame that is set by a slicer.
The Date slicer belongs to the Dates table in the Data model.
The table viz represents the number of rows in the sales table in the
current context (for each product within the Date range).
The table viz is sorted according to the [#Rows] measure in descending
order.
The table viz only presents the TopN products even without the presence
of the [#Rows] measure due to the presence of the [TopOrders]
measure within Filters on this visual. [TopOrders] is 1.
On the second page you create:
A slicer with the Dates[Date] column (the same one used on the
previous page).
A matrix with Products[ProductName] on the rows, HDates[Year] on
the columns, and a measure on values.
From the View tab, you select the Sync Slicers option.
Inside the Sync Slicers pane:
In the Sync column, check the boxes related to the necessary pages.
In the Display column uncheck the box that contains the over
years report.
So far all we have done is pass the time frame context from page 1 to page 2.
Since the TopN context depends on the time frame context, we can now use the [TopOrders] measure as a Filters on this visual in the matrix. Again, [TopOrders] is 1.
Why do the numbers differ between rows and not between columns?
Also, in this example, the Sales table only has information up to 12/31/2020 but the visualization shows an additional year and the Sales[Amount] values for each order is $1 so that [#Orders] and [SalesAmount] are the same for easy comparison.
HDates is not related to the model and for each combination of HDates[Year]-Products[ProductName], the [SalesAmount] measure is using the information coming from the previously hidden slicer and the respective Products[ProductName] because the information coming from HDates[Year] has no effect yet.
In order to complete this exercise, it only remains to modify the [SalesAmount] measure in such a way that it removes the filter on the time frame (Dates[Date]) and it recognizes HDates[Year] as Dates[Year].
SalesAmount :=
CALCULATE(
SUM(Sales[Amount]),
ALL(Dates),
TREATAS(VALUES(HDates[Year]),Dates[Year])
)
And this is the final result.
I hope it works for someone or the idea can be improved.

Create a pivot table in Power BI with dates instead of aggregate values?

I have a table of companies with descriptive data about where we are in the sales stage with the company, and the date we entered that specific stage. As can be seen below, the stages are rows in a Process Step column
My objective is to pivot this column so each Process Step is a column, with a date below it, as shown in excel:
I tried to edit the query and pivot the column upon loading it, but for the "aggregate value" column, no matter which column I use as the values column, it results in some form of error
My advice would be not to pivot the table in the query and use measures to get dates that you want. The benefit of not doing so is that you are able to perform all sorts of other analytics. For instance, Sankey chart would be hard to do properly with pivoted table.
To get the pivot table you are showing from Excel, it's as simple as using matrix visual in Power BI and putting Client code in rows and Process Step in Columns, then Effective date in values.
If you need to perform calculations between stages, it's also not too difficult. For instance, you can create a meausure that shows only dates at certain stages, another measure for another stage, and so on. For example:
Date uploaded = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Upload"))
Date exported = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Export"))
Time upload to export = DATEDIFF([Date uploaded], [Date exported], DAY)
These measures will work in the context of client and assuming there is only one date for the upload step (but no Process step in rows or columns). If another scenario is needed, perhaps a different approach could be taken.
Please let me know if that solves your problem.

Sort Months name Chronically in Descending order in Power BI

I have a very basic question in Power Bi I am trying to build a report in which I am using a Matrix Visual to display some data in the below format, However, I want the most recent months data to show first dynamically and then the following months after that, in this case show May first instead of Jan, Apr second instead of Feb and so on and so forth.
You can perform these below steps to achieve your required output-
Step 1:
Add a new custom column "month_name" (if not already available) in Power Query as shown in the picture. Please use the Date column from your source go generate the new column.
Step 2:
Add another custom column "year_month" as shown in the below image. Remember the target is to get the value like - "202001" (YYYYMM) from the date value. You can achieve the same with other conversion option as well. Please use the Date column from your source go generate the new column.
Step 3:
Change type of "year_month" column as Whole Number and get back to your report by clicking on the "Close & Apply" button.
Step 4:
Create a custom column "Rank" in the table as below-
Step 5:
Sort the "month_name" column using newly created column "rank" as shown in the below image-
Step 6:
Finally use the "month_name" column in your Matrix visual's column and this should be come up with your required output.
There is no option to sort matrix headers in power bi.
However there is a trick that you can apply in order to achieve this.
First Create a new column that referes your month column:
DescMonth = Table[Month]
Then create another column that keeps the order of the new column (you will need an ID Month column for this so be sure to create one if you haven't yet):
DescMonthOrder = - ( Table[IdMonth] )
Then sort the DescMonth column using the DescMonthOrder column
Finally use the DescMonth column in your matrix instead of the regular month column.
This way you will be able to achieve the following result:

PowerBI - Cumulative diagram with changing values

I am attempting to create a cumulative graph much like this one:
I have the following table in PowerBI
BugHistory
BugID
Date (date)
DateTo (date)
EntityStateName (text)
Effort (number)
I would like to do a measure that would tell me the amount of summed Effort on any given date for each EntityState.
I have tried quite a few things, even adding a Date Table using the Calendar, but getting the values to be shown correctly on a StackedGraph seems to be beyond me.
Hope someone can help.
Follow the following steps:
Right click on the column "Effort" and click the option called "New quick measure" in the right click menu.
In the window that appears, choose "Running Total" under the Calculation drop-down
This will show 3 new fields
In the Base Value field, drag and drop the "Effort" column
In the Field column drag and drop the "Date" column.
In the direction column choose Ascending
This will create a new measure in your Table. You can use that measure in you chart.
You can refer to the following video for reference: https://youtu.be/KlXclbN4oWE?t=497

Power bi box and whisker: filter with an if statement

MWE set up:
1) From the Power Bi visual website: https://app.powerbi.com/visuals/ there is a custom download "Box and Whisker (Jan Pieter)"
2) Download sample.
3) create new measure with dax formula:
Distinct count score = if(distinctCOUNT(Courses[Score]) > 4, average(Courses[Score]), Blank())
4) Add a Stacked column chart with Course as the axis and the newly created 'Distinct count score' as the Value and get the following:
5) compare this graph to the Box and Whisker provided by Power BI:
Here is my problem. I only want to show values in the Box and Whisker where the Distinct Count of Scores is greater than 4 -- So I only want Physics to show up (like the stacked column chart above).
So if I try the solution working with the stacked bar chart using the Dax formula. I get the following--nothing shows up:
And this is what I want to happen:
Question:
Is there a way in Power BI run and distinct count statement within a Box and Whisker chart to only show data with > 4 distinct values (or any if statement)?
I want it to be formula based, I cannot just 'visual filter' items I do not want.
Possible answer:
I thought about going to the source code to try and 'throw in' a if statement. But I went to the developers git hub: https://github.com/liprec -- I couldn't find the repo for this visual.
Basically this is due to the way the box and whisker chart is working. The visuals needs a dataset to calculate the values (mean, median, etc.) and use those values to show the box and whisker.
So in your case you need to create a measure that is on the same level as the scores (because those values are needed) and is only available. See the screenshot for a visual explanation of the needed measure.
I created the measure with the follow DAX measure:
Filter Score = IF(CALCULATE(DISTINCTCOUNT(Courses[Score]), ALLEXCEPT(Courses, Courses[Course]))>4, MIN(Courses[Score]), BLANK())
The Boolean expression of the IF statement calculates the distinct scores per course via a CALCULATE expression and the ALLEXCEPT filter option to ignore everything but the course value. And the TRUE part returns the score which needs to be aggregated, so the MIN and the FALSE part return a BLANK() value so is can be ignored.
When you add the new measure and create a BW chart it will only show 'Physics' course results.
If you need more help, please let me know here or via email.
-JP
BTW: I just updated my PowerBI visual GitHub repository (https://github.com/liprec/PowerBI-custom-visuals) and added my box and whisker chart and my hierarchy slicer to it in the folder oldAPI.
The crux of your problem, as far as I can tell, is that you want to filter visuals to courses that have a particular number of distinct values. Which visual you want to use is almost irrelevant (though it was helpful to have a sample Power BI workbook to follow along with).
The way I'd approach this (and not saying this is the best or only way)
Step 1
Create a new Course dimension table, with one row for each unique course. In the sample workbook, you can click 'Enter Data' and manually type in the data.
Course
------
English
Math
Physics
Step 2
Next, create a calculated column in the new table and calculate the distinct count for each course. This isn't a measure - it's a column in your table, that uses the Distinct Count calculation from your question.
Distinct Count = CALCULATE(DISTINCTCOUNT(Courses[Score]), SUMMARIZE('Courses','Courses'[Course]))
The SUMMARIZE works like a GROUP BY. In essence, creating one row per course with a distinct count of scores.
Step 3
Use this new attribute as a filter on your visual. You can then dynamically alter the number of distinct values as you feel like (4, 3, 2).
I know this isn't quite as good as typing a formula into the visual filter field, though in practice it's still formula driven. The formula is just on an underlying table.
Why so complex?
The reason you have to do this for the Box & Whiskers visual, whereas your 'Distinct Count score' measure works so well, is that on the column chart, you are displaying a single value (the average score). The Box & Whiskers chart, by contrast, is plotting every individual score.
In fact, if you removed the 'Course' from the axis of your column chart, the value changes as it adds back in the courses you filtered out. (The reason for this is that, if no course is on your axis, your formula calculates the distinct count of all the courses, which is 7). Likewise, if you were to filter your column chart to a particular session, your column chart would go blank (since in any given session, no course has more than 4 distinct values).
The technique I've described above fixes those problems, because it filters out the courses Math & English from the get-go. It doesn't matter if you've filtered to a single session, or not filtered by course at all. English & Math will always be excluded as long as their distinct count is below the value you specify.
Hope this helps.