I am quite new to Power BI and now facing a problem, illustrated below.
Here
**DATA**
LEVEL | PROJECT NAME| BUDGET_TYPE | BUDGET_CODE | BUDGET_AMOUNT
1 xxxx A 0000001 4,800,000
1 xxxx A 0000002 4,300,000
1 xxxx A 0000002 900,000
1 A 0000003 1,300,000
1 A 0000004 4,780,000
1 A 0000010 3,900,000
1 A 0000010 3,900,000
1 A 0000011 200,000
1 A 0000015 1,028,165
1 A 0000015 1,028,165
1 B 0000016 83,000,000
1 B 0000017 83,000,000
1 B 0000017 28,200,000
1 B 0000018 15,000,000
1 B 0000019 4,800,000
1 B 0000020 7,000,000
1 B 0000020 7,000,000
PIVOT TABLE from Excel
Row Labels | Max of BUDGET_AMOUNT
LEVEL: 1 83,000,000
TYPE:A 4,800,000
0000001 4,800,000
0000002 4,300,000
0000003 1,300,000
0000004 4,780,000
0000010 3,900,000
0000011 200,000
0000015 1,028,165 **20,308,165**
TYPE:B 83,000,000
0000016 83,000,000
0000017 83,000,000
0000018 15,000,000
0000019 4,800,000
0000020 7,000,000 **192,800,000**
Grand Total 83,000,000
I have raw data and PIVOT TABLE, respectively. What I want is to find MAX amount of each CODE first.
Then, SUM those MAX values only with distinct CODE.
I have attached the PIVOT TABLE for simplifying my problem. What I really want at the end is the SUM amount which is
LEVEL 1
TYPE A: 20,308,165
TYPE B: 192,800,000
Is there any way I can do that? Please help. Thanks!
You can do a measure that summarizes the different codes, calculates the max for each code, and sums up this table row-by-row:
Sum :=
VAR _tbl =
SUMMARIZE (
'Table' ,
'Table'[Level] ,
'Table'[Budget Code] ,
"Max Budget" , CALCULATE ( MAX ( 'Table'[Budget] ) )
)
RETURN
SUMX ( _tbl , [Max Budget] )
See minimal data example here:
I have the below table. I need to group them base on product and increment group number when set = 1 but returns back to 1 if new product is in next line. I have created an index already.
Index
Product
Set
1
Table
0
2
Table
0
3
Table
1
4
Table
0
5
Table
0
6
Table
1
7
Table
0
8
Table
1
9
Chair
0
10
Chair
0
11
Chair
0
12
Chair
1
13
Chair
0
14
Chair
0
15
Chair
1
Here's the result I'm after:
Index
Product
Set
Group
1
Table
0
1
2
Table
0
1
3
Table
1
1
4
Table
0
2
5
Table
0
2
6
Table
1
2
7
Table
0
3
8
Table
1
3
9
Chair
0
1
10
Chair
0
1
11
Chair
0
1
12
Chair
1
1
13
Chair
0
2
14
Chair
0
2
15
Chair
1
2
With this
Grouping=
RANKX (
FILTER (
'fact',
'fact'[Set] <> 0
&& EARLIER ( 'fact'[Product] ) = 'fact'[Product]
),
'fact'[Index],
,
ASC
Find all patients having compliance=0 from past consecutive 10 days from current date using Amazon Athena.
patient id compliance create_date
1 0 2021-01-01
1 0 2021-01-02
1 0 2021-01-03
1 0 2021-01-04--rejected not for consecutive 10
2 0 2021-01-01
2 0 2021-01-02
2 0 2021-01-03
2 0 2021-01-04
2 0 2021-01-05
2 0 2021-01-06
2 0 2021-01-07
2 0 2021-01-08
2 0 2021-01-09
2 0 2021-01-10-- accepted as for 10 consective
There are multiple ways to achieve this, and one can be to take the difference between a given date and the next one and check the cumulative sum of last X deltas (which is equal to 10 in your case) and the cumulative sum of your compliance integer on that row (which should be strictly equal to 0):
with base as (
select
*,
sum(delta) over (partition by patient_id rows between 10 preceding and current row) as cumdelta ,
sum(compliance) over (partition by patient_id rows between 10 preceding and current row) as cumcompliance
from (
select *, if (date_diff('day', date, next_date) is null, 1, date_diff('day', date, next_date)) as delta
from (
select
patient_id,
compliance,
try_cast(date as date) as date,
lead(date) over (partition by patient_id order by date) as next_date
from data
)
)
)
select
patient_id,
compliance,
date,
case when (cumdelta = 10 and cumcompliance = 0) then 'yes' else null end as validated_compliance
from base
i have a 2 tables that looks like this
Key |Num Of Treatments| Cost |
1 2 1000
1 2 1500
1 2 2000
2 3 700
3 3 800
4 4 900
key | limit |
1 1
2 1
3 2
4 3
the calculation that i want to do on dax is : (Num Of Treatments-Limit)*cost/Num Of Treatments
Assuming that the key column is unique for the second table (Table2 in dax).
Calculation =
VAR _limit =
LOOKUPVALUE ( Table2[limit], Table2[key], [key] )
RETURN
DIVIDE ( ( [Num Of Treatments] - _limit ) * [cost], [Num Of Treatments] )
This can be easily be achieved after creating one to many relationship between two tables with column Key.
Dax formula :
New Measure = ((SUM(Asset[No Of Treatments])-SUM(Tickets[Limit]))*SUM(Asset[Cost]))/SUM(Asset[No Of Treatments])
In a Panda's data frame, I'd like combine all 'other' rows from col_2 into a one row for each value from col_1 by assigning col_3 the sum of all corresponding values.
EDIT - Clarification: In total, I have about 20 columns (where values in those columns is unique for each col_1. there however 80,000 other fields; however, there are three columns affecting my question
Current dataframe df:
col_1 col_2 col_3
1 a 30
1 b 25
1 other 1
1 other 5
2 a 321
2 b 1
2 other 45
2 other 52
2 other 17
2 other 8
Desired resultin :
col_1 col_2 col_3
1 a 30
1 b 25
1 other 6
2 a 321
2 b 1
2 other 122
How can I do this in Pandas?
You can groupby on col_1 and col_2 and call sum and then reset_index:
In [188]:
df.groupby(['col_1','col_2']).sum().reset_index()
Out[188]:
col_1 col_2 col_3
0 1 a 30
1 1 b 25
2 1 other 6
3 2 a 321
4 2 b 1
5 2 other 122