Table 1
| | 1 Jan 2018 | 2 Jan 2018 | 3 Jan 2018 | 4 Jan 2018 | 5 Jan 2018 |
|----|------------|------------|------------|------------|------------|
| A1 | | | | | |
| A2 | | | | | |
| A3 | | | | | |
| A4 | | | | | |
| A5 | | | | | |
| A6 | | | | | |
Table 2
|----|----------|-----------|-----------|-----------|-----------|
| A1 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A2 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A3 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A4 | 3-Jan-18 | 6-Jan-18 | 10-Jan-18 | 13-Jan-18 | 17-Jan-18 |
| A5 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A6 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
IF MATCH
=IF(MATCH(A2,$A$27:$A$54,0) & MATCH(C1,$B$27:$S$54,0),"1","")
Getting #N/A error out of it
Trying to get apply formula onto the cells in Table 1 to lookup values in Table 2
If it matches, output is 1, else 0
Table & Image above to clearly illustrate & experiment out.
Thanks in advance (:
Applied formula & Output
Firstly, MATCH() returns a number that represents the position of a found match so your formula says IF(1 & 1,"1","") for your first potential match, there is no logical here.
The first ammendment would be to force a True / False output: =IF(AND(ISNUMBER(MATCH()),ISNUMBER(MATCH())),"1","")
You still have the issue that the second match is referencing the entire range of resuts though, you really want this to only look through the row that meets the first criteria, for this we will use an array formula to build the array you want to use:
EDIT: You can't buld an array from Match as it returns a single integer:
=LARGE(IF(B$1=IF($A2=$A$27:$A$54,$B$27:$S$54),1,0),1)
This is an array formula, while still in the formula bar hit Ctrl+Shift+Enter
The Inner IF() statemnet is building an array of each row, providing values where column A matches and FALSE where it doesn't. The outter IF() statement is then evaluating 0 or 1 whether it finds the date in that new array...
I have wrapped this in a LARGE() to return the first largest number so if a single match is found it will return that 1. If you want the blank you can wrap the whole thing in another IF() statement; IF([formula]=0,"",1)
Related
i have a data for group no and its set value. When the set value is same for all the batches i dont want those batches to be counted. but if there are more than 1 set values in each batch then the dax query should count it as 1.
My current data is like this
| group_no | values |
| ---------- | ---------------------- |
| H110201208 | 600 |
| H110201208 | 600 |
| H110201208 | 680 |
| H101201215 | 665 |
| H109201210 | 640 |
| H123201205 | 600 |
| H125201208 | 610 |
| H111201212 | 610 |
| H111201212 | 630 |
I want my output like this
| Group no | Grand Total |
| ---------- | ----------- |
| H101201215 | 1 |
| H109201210 | 1 |
| H110201208 | 3 |
| H111201212 | 2 |
| H123201205 | 1 |
| H125201208 | 1 |
i want to create another table like the one above using dax so that i can plot graphs n percentages based on its output
i want to do this in powerbi using DAX language.
TABLE =
GROUPBY (
Groups, //SourceTable
Groups[ group_no ],
"GrandTotal", COUNTX ( CURRENTGROUP (), DISTINCTCOUNTNOBLANK ( Groups[ values ] ) )
)
I am working on making sure a form input is parsed correctly through google forms and I was trying to use my limited regex knowledge to make sure that people do not input tracts incorrectly.
usually a tract is given in an example such as 5129.01
All tracts in the county start with 5, have a second character that is either a 0 or a 1,and if it is a 1, the third character is either [0 - 3] else its [0-9].
I have a working expression but I would like to ensure that if the second character is a 1 the user wouldn't be able to enter a tract like 5150.01
This is what I have:
^5[0-1]([0-9]{2})(\.([0-9]{2}))?$
and this is what is not working:
^5[0-1](?(?<=1)\d|[0-3])(\.([0-9]{2}))?$
Any help would be appreciated thanks
I hope this answers your question, please comment and I can edit accordingly.
The pattern:
^(?:51[0-3]|50[0-9])[0-9](?:\.[0-9]{1,2})?$
A visual representation:
HTML implementation:
<input name="example" pattern="^(?:51[0-3]|50[0-9])[0-9](?:\.[0-9]{1,2})?$">
Value validation examples:
+----------+--------+
| Value | Status |
+----------+--------+
| 51 | fail |
| 510 | fail |
| 5101 | pass |
| 5111 | pass |
| 5121 | pass |
| 5131 | pass |
| 5141 | fail |
| 5102. | fail |
| 5102.1 | pass |
| 5102.12 | pass |
| 5102.123 | fail |
| 50 | fail |
| 500 | fail |
| 5001 | pass |
| 5011 | pass |
| 5021 | pass |
| 5031 | pass |
| 5041 | pass |
| 5051 | pass |
| 5061 | pass |
| 5071 | pass |
| 5081 | pass |
| 5091 | pass |
| 50911 | fail |
| 5092. | fail |
| 5092.1 | pass |
| 5092.12 | pass |
| 5092.123 | fail |
+----------+--------+
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 have a Django model with three fields: product, condition and quantity with data such as:
| Product | Condition | Quantity |
+---------+-----------+----------+
| A | new | 2 |
| A | new | 3 |
| A | new | 4 |
| A | old | 1 |
| A | old | 2 |
| B | new | 2 |
| B | new | 3 |
| B | new | 1 |
| B | old | 4 |
| B | old | 2 |
I'd like to sum the quantities of the entries where product and condition are equal:
| Product | Condition | Quantity |
+---------+-----------+----------+
| A | new | 9 |
| A | old | 3 |
| B | new | 6 |
| B | old | 6 |
This answer helps to count entries with the same field value, but I need to count two fields.
How could I implement this?
from django.db.models import Sum
Model.objects.values('product', 'condition').order_by().annotate(Sum('quantity'))
First time post so hopefully someone can kindly assist on this problem I'm facing within SAS EG (still learning SAS coding so please be kind!)
If you see a snippet of the dataset below what I'm trying to do is tally up the scores (pts) by Ref based on consecutive occurrences that flag has showed for that Ref.
For Example:
If you take Ref 505 for A_Flag there is 2 different sets of consecutive occurrences of that flag then scoring will be as follows:
1st ID > 1st instance = 25 points
2nd ID > 2nd instance but 1st consecutive instance = double to 50 points
3rd ID > 0 instance = 0 points
4th ID > 1st instance = 25 points
5th ID > 2nd instance but 1st consecutive instance = double to 50 points
6th ID > 0 instance = 0 points
Therefore for this Ref A_Pts will be 150 points.
Another example:
If you take Ref 527 for B_Flag there is 4 consecutive occurrences of that flag so coring per ID:
1st ID > 0 instance = 0 points
2nd ID > 1st instance = 10 points
3rd ID > 2nd instance but 1st consecutive instance = double to 20 points
4th ID > 3rd instance but 2nd consecutive instance = double to 40 points
5th ID > 4th instance but 3rd consecutive instance = double to 80 points
Therefore for this Ref B_Pts will be 150 points
I have to say the data is in the necessary order for what I'm trying to achieve.
I'd tried using LAG function but that will only work based on the 1st consecutive instance.
I also tried calculate a count - an enumeration variable based on cats(Ref,A_Flag) - but it then orders the data incorrectly and doesnt count up accordingly
Hopefully this makes sense to someone out there!
The dataset in question:
+-----------+-----+--------+--------+--------+-------+-------+
| date | Ref | FormID | A_Flag | B_Flag | A_Pts | B_Pts |
+-----------+-----+--------+--------+--------+-------+-------+
| 01-Feb-17 | 505 | 74549 | A | | 25 | 0 |
| 01-Feb-17 | 505 | 74550 | A | | 25 | 0 |
| 10-Jan-17 | 505 | 82900 | | B | 0 | 10 |
| 13-Jan-17 | 505 | 82906 | A | | 25 | 0 |
| 09-Jan-17 | 505 | 82907 | A | | 25 | 0 |
| 11-Jan-17 | 505 | 82909 | | B | 0 | 10 |
| 03-Jan-17 | 527 | 62549 | A | | 25 | 0 |
| 04-Jan-17 | 527 | 62550 | | B | 0 | 10 |
| 04-Jan-17 | 527 | 76151 | | B | 0 | 10 |
| 04-Jan-17 | 527 | 76152 | A | B | 25 | 10 |
| 04-Jan-17 | 527 | 76153 | A | B | 25 | 10 |
+-----------+-----+--------+--------+--------+-------+-------+
Desired output (unless there is a better suggestion):
+-----------+-----+--------+--------+--------+-----------+-----------+
| date | Ref | FormID | A_Flag | B_Flag | A_Pts_Agg | B_Pts_Agg |
+-----------+-----+--------+--------+--------+-----------+-----------+
| 01-Feb-17 | 505 | 74549 | A | | 25 | 0 |
| 01-Feb-17 | 505 | 74550 | A | | 50 | 0 |
| 10-Jan-17 | 505 | 82900 | | B | 0 | 10 |
| 13-Jan-17 | 505 | 82906 | A | | 25 | 0 |
| 09-Jan-17 | 505 | 82907 | A | | 50 | 0 |
| 11-Jan-17 | 505 | 82909 | | B | 0 | 10 |
| 03-Jan-17 | 527 | 62549 | A | | 25 | 0 |
| 04-Jan-17 | 527 | 62550 | | B | 0 | 10 |
| 04-Jan-17 | 527 | 76151 | | B | 0 | 20 |
| 04-Jan-17 | 527 | 76152 | A | B | 25 | 40 |
| 04-Jan-17 | 527 | 76153 | A | B | 50 | 80 |
+-----------+-----+--------+--------+--------+-----------+-----------+
So when totalled up it'll be
+-----+-----------+-----------+
| Ref | A_Pts_Agg | B_Pts_Agg |
+-----+-----------+-----------+
| 505 | 150 | 20 |
| 527 | 100 | 150 |
+-----+-----------+-----------+
Try this:
data have;
infile cards dlm='|';
input date :date7. Ref :8. FormID :8. A_Flag :$1. B_Flag :$1. A_Pts :8. B_Pts :8.;
format date date7.;
cards;
| 01-Feb-17 | 505 | 74549 | A | | 25 | 0 |
| 01-Feb-17 | 505 | 74550 | A | | 25 | 0 |
| 10-Jan-17 | 505 | 82900 | | B | 0 | 10 |
| 13-Jan-17 | 505 | 82906 | A | | 25 | 0 |
| 09-Jan-17 | 505 | 82907 | A | | 25 | 0 |
| 11-Jan-17 | 505 | 82909 | | B | 0 | 10 |
| 03-Jan-17 | 527 | 62549 | A | | 25 | 0 |
| 04-Jan-17 | 527 | 62550 | | B | 0 | 10 |
| 04-Jan-17 | 527 | 76151 | | B | 0 | 10 |
| 04-Jan-17 | 527 | 76152 | A | B | 25 | 10 |
| 04-Jan-17 | 527 | 76153 | A | B | 25 | 10 |
;
run;
data want;
set have;
by Ref;
retain A_pts_agg B_pts_agg;
if first.Ref then do;
A_pts_agg = A_pts;
B_pts_agg = B_pts;
end;
if lag(A_flag) ne (A_flag) then A_pts_agg = A_pts;
else if A_flag = 'A' then A_pts_agg = A_pts_agg * 2;
if lag(B_flag) ne (B_flag) then B_pts_agg = B_pts;
else if B_flag = 'B' then B_pts_agg = B_pts_agg * 2;
run;