I am having a hard time getting the following measure to work. I am trying to change the target based on a date filter. My filter is the Workday columns, where Workday is a standard date column. sMonth is a month columns formatted as whole number. I am looking to keep the slicer granular, in order to work by day, adding custom columns with month and year and basing the measure on those would help. This is what I have tried and couldn't get it to work:
Cars Inspected =
VAR
selectedMonth = MONTH(SELECTEDVALUE('All Cars Inspected'[Workday]))
RETURN CALCULATE(SUM(Targets[Target]),
FILTER(Targets,Targets[Location]="Texas"),
FILTER(Targets,Targets[Description]="CarsInspected"),
FILTER(Targets,Targets[sMonth]=selectedMonth))
I would appreciate if someone would suggest a different way of achieving the same result.
LE:
This is a mock-up of what I am trying to achieve:
The total cars get filtered by the Workday. I would like to make the Targets/Ranges dynamic. When the slider gets adjusted everything else is adjusted.
My tables look like this:
+-----------+--------------------+----------+
| Workday | TotalCarsInspected | Location |
+-----------+--------------------+----------+
| 4/4/2017 | 1 | Texas |
| 4/11/2017 | 149 | Texas |
| 4/12/2017 | 129 | Texas |
| 4/13/2017 | 201 | Texas |
| 4/14/2017 | 4 | Texas |
| 4/15/2017 | 6 | Texas |
+-----------+--------------------+----------+
+----------+--------+----------+---------------+--------+-----+--------+
| TargetID | sMonth | Location | Description | Target | Red | Yellow |
+----------+--------+----------+---------------+--------+-----+--------+
| 495 | 1 | Texas | CarsInspected | 3636 | 0.5 | 0.75 |
| 496 | 2 | Texas | CarsInspected | 4148 | 0.5 | 0.75 |
| 497 | 3 | Texas | CarsInspected | 4861 | 0.5 | 0.75 |
| 498 | 4 | Texas | CarsInspected | 4938 | 0.5 | 0.75 |
| 499 | 5 | Texas | CarsInspected | 5094 | 0.5 | 0.75 |
| 500 | 6 | Texas | CarsInspected | 5044 | 0.5 | 0.75 |
| 501 | 7 | Texas | CarsInspected | 5043 | 0.5 | 0.75 |
| 502 | 8 | Texas | CarsInspected | 4229 | 0.5 | 0.75 |
| 503 | 9 | Texas | CarsInspected | 4311 | 0.5 | 0.75 |
| 504 | 10 | Texas | CarsInspected | 4152 | 0.5 | 0.75 |
| 505 | 11 | Texas | CarsInspected | 3592 | 0.5 | 0.75 |
| 506 | 12 | Texas | CarsInspected | 3748 | 0.5 | 0.75 |
+----------+--------+----------+---------------+--------+-----+--------+
Let the Value for your gauge be the sum of TotalCarsInspected and set the Maximum value to the following measure:
Cars Inspected =
VAR selectedMonth = MONTH(MAX('All Cars Inspected'[Workday]))
RETURN LOOKUPVALUE(Targets[Target],
Targets[Location], "Texas",
Targets[Description], "CarsInspected",
Targets[sMonth], selectedMonth)
Related
I am working on Cost of goods sold using Powerbi.
https://www.mediafire.com/file/pmb7u1thsag1kq1/Cost+of+goods+sold.pbix/file
Above is my file which i uploaded on mediafire.
i am taking the average price by using average function year wise.
If you see in File.
| GName | Year | Opening Stock | InQty | OutQty | InItemValue | Average Value | Closing Stock | Closing Stock Value | Opening Stock Value | Cost of Goods Sold |
|-------------|------|---------------|-------|--------|-------------|---------------|---------------|---------------------|---------------------|--------------------|
| Bahria Town | 2016 | | 4454 | 3586 | 126610299.8 | 28426.20113 | 868 | 24673942.58 | 0 | 101936357.2 |
| Bahria Town | 2017 | 868 | 6379 | 6547 | 166903971.5 | 23030.76743 | 700 | 16121537.2 | 0 | 150782434.3 |
| Bahria Town | 2018 | 700 | 9129 | 8709 | 271932546.3 | 27666.3492 | 1120 | 30986311.11 | 0 | 240946235.2 |
| Bahria Town | 2019 | 1120 | 9333 | 9393 | 313226466.8 | 29965.22212 | 1060 | 31763135.45 | 0 | 281463331.4 |
| Bahria Town | 2020 | 1060 | 10192 | 10136 | 362950101.2 | 32256.49673 | 1116 | 35998250.35 | 0 | 326951850.8 |
| Bahria Town | 2021 | 987 | 8882 | 8468 | 404199067.4 | 40956.43605 | 1530 | 62663347.16 | 0 | 346819100.5 |
In Above as you can see i just took the Average Value
Average Value = ([Opening Stock Value]+[initemvaluee])/([inqtyy]+[Opening Stock])
and closing stock value
Closing Stock Value = [Average Value] * [Closing Stock]
When i calculate the closing stock value of previous year its give me error.
circular dependency was detected: Measure: 'mak_stockInHandValue'[Average Value], Measure: 'mak_stockInHandValue'[Opening Stock Value], Measure: 'mak_stockInHandValue'[Average Value].
Any Suggestion to see the closing stock value in the field of opening stock value ?????
I am working on this from more than 2 weeks.
Please help me out
Thanks in advance
Could you please help me to solve the problem as I am totally new to DAX and English is not my first language so I am struggling to even find the correct question.
Here's the problem.
I have two tables:
start_balance
+------+---------------+
| Type | Start balance |
+------+---------------+
| A | 0 |
| B | 10 |
+------+---------------+
in_out
+------+-------+------+----+-----+
| Year | Month | Type | In | Out |
+------+-------+------+----+-----+
| 2020 | 1 | A | 20 | 20 |
| 2020 | 1 | A | 0 | 10 |
| 2020 | 2 | B | 20 | 0 |
| 2020 | 2 | B | 20 | 10 |
+------+-------+------+----+-----+
I'd like to get the result as follows:
Unfiltered:
+------+-------+------+---------+----+-----+------+
| Year | Month | Type | Balance | In | Out | Left |
+------+-------+------+---------+----+-----+------+
| 2020 | 1 | A | 0 | 20 | 20 | 0 |
| 2020 | 1 | B | 10 | 20 | 10 | 20 |
| 2020 | 2 | A | 0 | 20 | 10 | 10 |
| 2020 | 2 | B | 20 | 20 | 10 | 30 |
+------+-------+------+---------+----+-----+------+
Filtered (for example year/month 2020/2):
+------+-------+------+---------+----+-----+------+
| Year | Month | Type | Balance | In | Out | Left |
+------+-------+------+---------+----+-----+------+
| 2020 | 2 | A | 0 | 20 | 10 | 10 |
| 2020 | 2 | B | 20 | 20 | 10 | 30 |
+------+-------+------+---------+----+-----+------+
So while selecting a slicer for the year/month it should calculate balance before selected year/month and then show selected year/month values.
Edit: corrected start_balance table.
Is the sample data correct?
A -> the starting balance is 10, but in your unfiltered table example, it is 0.
Do you have any relationship between these tables?
Does opening balance always apply to the current year? What if 2021 appears in the in_out table? How do you know when the start balance started?
example without starting balance
If you want to show value breaking given filter you should use statement ALL or REMOVEFILTERS function (in Analysis Services 2019 and in Power BI since October 2019).
calculate(sum([in]) - sum([out]), all('in_out'[Year],'in_out'[Month]))
More helpful information:
https://www.sqlbi.com/articles/managing-all-functions-in-dax-all-allselected-allnoblankrow-allexcept/
I've spend hours trying different combinations of SWITCH(True...) and subtractions to correctly calculate this but cannot find a solution.
For example, I have the following thresholds for X amount of hours:
0-400: 10%
401-1000: 17%
1001-1300: 20%
1301-1675: 25%
1675-2500: 30%
2501 and above: 35%.
Please find below a simple example breakdown:
| Hours | 10% | 15% | 20% | 25% | 30% | 35% |
|-------|-----|-----|-----|-----|-----|-----|
| 1400 | 400 | 600 | 300 | 100 | | |
| 2600 | 400 | 600 | 300 | 375 | 825 | 100 |
| 3000 | 400 | 600 | 300 | 375 | 825 | 500 |
| Year | MonthNo | Hours | Amount |
|------|---------|-------|--------|
| 2020 | 8 | 970 | 48500 |
| 2020 | 7 | 1400 | 70000 |
| 2020 | 6 | 2600 | 130000 |
| 2020 | 5 | 3000 | 150000 |
The first 2 are easy to accomplish but I cannot cover all the rules. How can accomplish this in DAX and multiply by the correct percentage?
There is no percentage table, the percentage's would be applied to the amount as a rebate and then added up according to the thresholds. E.g:
+-------------+------+------+------+--------+-------+-----+-----+
| Percentages | | 10% | 15% | 20% | 25% | 30% | 35% |
+-------------+------+------+------+--------+-------+-----+-----+
| Hours | 1400 | 400 | 600 | 300 | 100 | | |
| Amount | 7000 | 2000 | 5100 | 3000 | 1500 | | |
| | | | | rebate | 11600 | | |
+-------------+------+------+------+--------+-------+-----+-----+
I have a time-series data in my table. Sample Data given below:
+------+------------+-----------+-----------+-------------+-------------+
| CODE | YEAR_MONTH | CALC_LVL1 | CALC_LVL2 | MSRMT_PCT_1 | MSRMT_PCT_2 |
+------+------------+-----------+-----------+-------------+-------------+
| A1 | 201912 | 87 | 564 | 0.14 | 0.1 |
| A1 | 201911 | 34 | 455 | 0.15 | 0.08 |
| A1 | 201910 | 20 | 295 | 0.1 | 0.14 |
| A1 | 201909 | 39 | 219 | 0.08 | 0.14 |
| A1 | 201908 | 98 | 438 | 0.14 | 0.11 |
| A1 | 201907 | 7 | 219 | 0.08 | 0.14 |
| A1 | 201812 | 63 | 564 | 0.14 | 0.17 |
| A1 | 201808 | 12 | 455 | 0.15 | 0.13 |
| A1 | 201805 | 48 | 409 | 0.13 | 0.13 |
| A1 | 201802 | 88 | 289 | 0.11 | 0.08 |
| A1 | 201801 | 9 | 492 | 0.14 | 0.13 |
+------+------------+-----------+-----------+-------------+-------------+
Is there any way that the default chart shows me the year values, and when user clicks on a year label, then it shows monthly data?
I am assuming you are looking for Time Axis chart where the chart label is mapped to the DATE or TIMESTAMP column. In the chart attributes, set the Time Axis Type to Enabled. Labels will then be correctly rendered as readable dates. You can then build another chart or report that can be drilled down from this chart. To do this, navigate to the chart, select the series and then in the property editor, navigate to Column Mapping. Select the column names for LABEL and VALUE. For Link > Type, select Redirect to Page in this application. Click Target, select the page and set page item and value.
I need to rank products for my dashboard. Each day, we store sales of products. In result we have this dataset example:
+-----------+------------+-------+
| product | date | sales |
+-----------+------------+-------+
| coffee | 11/03/2019 | 15 |
| coffee | 12/03/2019 | 10 |
| coffee | 13/03/2019 | 28 |
| coffee | 14/03/2019 | 1 |
| tea | 11/03/2019 | 5 |
| tea | 12/03/2019 | 2 |
| tea | 13/03/2019 | 6 |
| tea | 14/03/2019 | 7 |
| Chocolate | 11/03/2019 | 30 |
| Chocolate | 11/03/2019 | 4 |
| Chocolate | 11/03/2019 | 15 |
| Chocolate | 11/03/2019 | 10 |
+-----------+------------+-------+
My attempt
I actualy managed to Rank my products but not in the way I wanted it; In fact, the ranking process increase by the number of rows. for example, chocolate is first but we record 4 rows so coffee is ranked at 5 and not 2.
+-----------+------------+-------+-----+------+
| product | date | sales | sum | rank |
+-----------+------------+-------+-----+------+
| coffee | 11/03/2019 | 15 | 54 | 5 |
| coffee | 12/03/2019 | 10 | 54 | 5 |
| coffee | 13/03/2019 | 28 | 54 | 5 |
| coffee | 14/03/2019 | 1 | 54 | 5 |
| tea | 11/03/2019 | 5 | 20 | 9 |
| tea | 12/03/2019 | 2 | 20 | 9 |
| tea | 13/03/2019 | 6 | 20 | 9 |
| tea | 14/03/2019 | 7 | 20 | 9 |
| Chocolate | 11/03/2019 | 30 | 59 | 1 |
| Chocolate | 11/03/2019 | 4 | 59 | 1 |
| Chocolate | 11/03/2019 | 15 | 59 | 1 |
| Chocolate | 11/03/2019 | 10 | 59 | 1 |
+-----------+------------+-------+-----+------+
sum field formula formula:
sum =
SUMX(
FILTER(
Table1;
Table1[product] = EARLIER(Table1[product])
);
Table1[sales]
)
rank field formula :
rank = RANKX(
ALL(Table1);
Table1[sum]
)
As you can see, we get the following ranking:
1 : Chocolate
5 : Coffee
9 : Tea
Improvements
I would like to transform the previous result into :
1 : Chocolate
2 : Coffee
3 : Tea
Can you help me improving my ranking system and get a marvelous 1, 2, 3 instead of this ugly and not practical 1, 5, 9 ?
If you don't know the anwser, help by simply upvote the question ♥
Fortunately, this is an easy fix.
If you look at the documentation for the RANKX function, you'll notice an optional ties argument which you can set to Skip or Dense. The default is Skip but you want Dense. Try this:
rank =
RANKX(
ALL(Table1);
Table1[sum];
;;
"Dense"
)
(Those extra ; delimiters are there since we aren't specifying the optional value or order arguments.)