The goal is to create a visual that shows Budget vs Premium for each month in a year; Something like that:
So I have two tables BudgetData and Premiums. How can I join those two table on two columns:
`BudgetData.InsurenceType = Premiums.Division
and
BudgetData .MonthYear = Premiums.MonthYear`
BudgetDate Table:
InsurType Amount MonthYear
Commercial Auto 1000 Jan 2017
Commercial Auto 22000 Feb 2017
Commercial Auto 3000 Mar 2017
Specialty Casualty 4000 Jan 2017
Specialty Casualty 5000 Feb 2017
Specialty Casualty 35000 Mar 2017
Premiums Table:
Division Premium MonthYear
Commercial Auto 2500 Jan 2017
Commercial Auto 1800 Feb 2017
Commercial Auto 3365 Mar 2017
Specialty Casualty 14528 Jan 2017
Specialty Casualty 3323 Feb 2017
Specialty Casualty 1825 Mar 2017
In Power BI I can only join on single relationship, which is I dont understand why its made that way.
So what would be the most efficient way to achieve that? In terms of performance.
UPDATE:
Joe, thank you very much.
I was able to join.
But when I try to do the visual it gives me Budget Amount either count
or sum
I set Don't summarize
and made sure datatypes are the same with Premium value (Decimal Number) but still having this issue.
Is it something to do with join?
UPDATE2:
.pibx file is avalable via dropbox: https://www.dropbox.com/s/mcj1gtonttjtz6y/PremiumByDivisions.pbix?dl=0
UPDATE 3
Joe, what if I create separate calculated table from existing tables Premiums
and BudgetData
with columns: Premium
, BudgetAmount
, Division
and MonthYear
.
Somehting like that:
Then use it in my chart. Do you think it will filter by Division if I click on Donut chart?
The problem is I know how to create such table in SQL, but dont know how to do that in DAX. Below is t-sql code:
;with cte_Premiums
as
(
select sum(Premium) as Premium,
Division,
LEFT(DATENAME(MONTH,[EffectiveDate]),3) +' '+ CONVERT(varchar(4),Year(EffectiveDate)) AS MonthYear,
MAX(DATEPART(MM, [EffectiveDate])) as DateOrder
from ##OlegTest
group by LEFT(DATENAME(MONTH,[EffectiveDate]),3) +' '+ CONVERT(varchar(4),Year(EffectiveDate)), Division
)
,cte_Budget
AS
(
select insurType,
Amount,
LEFT(DATENAME(MONTH,[PostDate]),3) +' '+CONVERT(varchar(4),Year([PostDate])) AS MonthYear
from BudgetData
)
select Premium,
Amount as BudgetAmount,
Division,
p.MonthYear
FROM cte_Premiums p INNER JOIN cte_Budget b ON p.Division = b.insurType and p.MonthYear = b.MonthYear
ORDER BY Division,DateOrder