Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi PowerBI experts!
I'm relatively new on using GROUPBY and I am confused on how it works. Apologies for the lack of knowledge.
Problem: I am building a report in which an account number has multiple transactions. The values that were provided are as follows.
A. Base Date - a date that is static for every account number;
B. Transaction Dates - the dates that are logged everytime an account number has made a transaction;
C. Account Number - The # of account numbers is atleast 40k that is why I'm not able to use LOOKUPVALUE for this one.
Screenshot A:
STEPS DONE
Step 1. I have managed to create a DATEDIFF to calculate the difference between the BASE DATE and TRANSACTION DATE. In this way, I was able to check which TRANSACTION DATE is closest to the BASE DATE.
Step 2. Next step is to create a MIN field for the datediff. This is where I am currently stuck at. The calculation I made for MIN DAYDIFF treats each row as an individual record. I'm sure that I should be using the GROUPBY calculation here but I'm not sure on how it generally works.
I
What I want to achieve: The goal of this report is to create a flag field in which it will tell the user that this TRANSACTION DATE of an ACCOUNT NUMBER is the one closest to the value of the BASE DATE.
I have the logic but I am lacking the execution part.
Logic: MIN(DayDiff) GROUPBY member acc
Screenshot 😧
Step 3. After creating the MIN DAYDIFF. I need to create a calculation with the following logic. This will serve as the flag in which I will be able to continue developement of the report. I also noted that there are some TRANSACTION DATE that are not matching with BASE DATE, so I need to get its MIN value. (see screenshot E)
[FLAG] = IF ( 'Table'[DAYDIFF] = 'Table'[MIN DAYDIFF] , 1, 0)
Screenshot E
I really appreciate for any suggestions on how to build this one. Thank you!
-James
Solved! Go to Solution.
hi, @ja1meee
try below code
Here
'Table'[day diff] is calculated column and code is below
for download .pbix file of this solution click HERE
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. and don't forget to give kudos
Hi, @ja1meee
Try below code for
Just adjust your table and column name
Min DayDiff =
Calculate (min('Sample'[DayDiff]),
allexcept('yourtablename',
'yourtablename'[member acc]))
These will help that you want
After your flag logic work
[FLAG] = IF ( 'Table'[DAYDIFF] = 'Table'[MIN DAYDIFF] , 1, 0)
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. and don't forget to give kudos.
Hi @Dangar332 ! The Min DayDiff worked wonders for me. Thank you! However I am having an issue on the flag. Kindly look on the calculation I made for the flag calculation.
For reference, this is the result that I want to achieve:
Thank you
-James
hi, @ja1meee
hi, @ja1meee
these is updated code
hi, @ja1meee
try below code
Here
'Table'[day diff] is calculated column and code is below
for download .pbix file of this solution click HERE
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. and don't forget to give kudos
Thank you very much @Dangar332! This works very well in the report. For reference, the DAYDIFF field I created was a calculated column.
Please see result on my end:
User | Count |
---|---|
57 | |
21 | |
21 | |
19 | |
16 |
User | Count |
---|---|
86 | |
84 | |
52 | |
37 | |
23 |