The Semantic Model
moving straight on from Part 8. We were in the SQL Analytics Endpoint.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-173.png?w=255)
At the bottom of the screen we have a model view. This is the Default Model view
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-174.png?w=1024)
This takes us to the Semantic Model
Semantic Modelling in Fabric
Lets update the default semantic model. Set the relationships. Hide Keys, set up Orders, hierarchies etc.
Direct lake
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-175.png?w=248)
Notice the Storage model is Direct Lake. this has greatly reduced the amount of copies of the data we have. Power BI is using the PARQUET files in the same way it would Import into the Columnar Power BI data Store.
Direct lake is only available with Microsoft Fabric and Delta PARQUET tables
Unfortunately I have hit a problem.
The Semantic Model isn’t working. After every change we hit
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-176.png?w=729)
‘We cannot access source column ‘<ccon>series</ccon>’ from delta table ‘<ccon>dimepisode</ccon>
However, checking the Data and series is available.
Also the directions on the join are incorrect (Before the changes are removed)
After looking at some of these issues online, it would appear that currently the ‘default’ semantic model is very glitchy and many people are having issues with it.
People are using work arounds by creating their own semantic models rather than using the default. This seems very disappointing, and I hope its rectified soon (As at 30/05/2024)
https://powerbi.microsoft.com/en-gb/blog/improvements-for-creating-new-direct-lake-semantic-models/
Create a Semantic Model
Back in the Lakehouse
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-177.png?w=266)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-178.png?w=167)
Choose New Semantic Model
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-180.png?w=645)
Select All
Join Dim Episode to Episode Key
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-181.png?w=679)
Immediately we see an issue. the many should be on the fact side.
Time to go back to the SQL analytics endpoint to quickly check what is happening.
Going back to My Queries and the Taskmaster data checks file.
SELECT f.TaskKey AS FactTaskKey, COUNT(*)
FROM [DebbiesFabricLakehouse].[dbo].[facttaskmaster] f
GROUP BY f.TaskKey
SELECT t.TaskKey AS DimTaskKey, COUNT(*)
FROM [DebbiesFabricLakehouse].[dbo].[dimtask] t
GROUP BY t.TaskKey
Having COUNT(*) > 1
SELECT Task, TaskOrder, COUNT(*) FROM [DebbiesFabricLakehouse].[dbo].[dimtask]
GROUP BY Task, TaskOrder
HAVING COUNT(*) > 1
it would seem that from running the above queries. Everything is correct. 1 Task to Many. In Power BI desktop this would automatically create the correct relationship for you,
So in this instance, go into the relationship and reset. (is this an issue in Fabric at the moment?)
Relationships and hiding keys
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-182.png?w=1024)
Friendly Names
Now I want to set up Friendly names for the columns and tables. If we change a table name in Data, how does this affect the DELTA PARQUET table? Lets check.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-183.png?w=135)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-184.png?w=210)
it doesn’t affect Delta PARQUET file so lets add Friendly names into the model for the dims
E.g.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-185.png?w=271)
Add Sort orders and hide
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-186.png?w=555)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-187.png?w=223)
This has been repeated on :
- Dim Date Quarter / Quarter No
- Dim Episode Episode Name / Episode No
- Dim Task Task / Task Order
Hierarchies
Dim Date
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-189.png?w=570)
Hide the original fields outside of the hierarchy so not to confuse the user.
For this project, Lets not use Quarter and hide it for the time being
Lets also hide financial year
Dim episode
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-190.png?w=263)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-191.png?w=284)
Don’t forget to click Apply level changes
DAX
Now we can start to add the DAX. The question here is, In power BI Desktop we can create DAX and then immediately create a visual to check its looking good. how do we do this in the Semantic model in Fabric?
Points
Total Points = SUM(‘fact Taskmaster'[Points])
And hide the base metric
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-192.png?w=229)
And add the new DAX to a Folder
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-195.png?w=268)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-196.png?w=216)
So how do we quickly check this
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-193.png?w=58)
Using the new report we can quickly create a test report.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-194.png?w=526)
No need to save this report. it is just a tester.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-197.png?w=770)
There is something wrong with the Date connection. We can go back to the SQL analytics Endpoint to quickly check (After checking the relationships)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-198.png?w=397)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-199.png?w=1024)
Our Date Dimension starts in 2020, and we are only at 2017 so the Date Delta PARQUET needs an update.
Dim Date NoteBook
Back in Dim Date. All we need to do here is to reconfigure these Start and End Dates
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-200.png?w=1024)
# Define your start and end dates
start_date = '2015-01-01'
end_date = '2027-12-21'
And rerun the entire notebook
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-201.png?w=129)
then go back to the Query just jun.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-202.png?w=1024)
And after a refresh on the report
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-203.png?w=402)
Great. this issue has now been resolved.
Week
And whilst in Dim Date Dimension. there is one thing that we havent added and thats week.
Week is really important because each Each episode is once a week. Its more important than day. So lets quickly update to bring in a Week column and we can update the hierarchy and hide day.
from pyspark.sql.functions import to_date, weekofyear
dfDateWeek = dfdate2.withColumn('weekofyear', weekofyear(dfdate2.date))
dfDateWeek.show()
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-204.png?w=1024)
And Update the Creation of the files to use this dataframe
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-205.png?w=919)
Update the date Hierarchy
Once set lets go back to the semantic model
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-206.png?w=426)
Right click and Refresh
This didn’t work. Week of year isn’t appearing in the model.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-207.png?w=65)
Clicking this seems to have worked.
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-208.png?w=269)
We don’t want to sum up the weeks so in Properties / Advanced, set summarize by to None.
Update the hierarchy
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-211.png?w=561)
Also, Don’t forget to set as Date table
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-209.png?w=270)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-210.png?w=804)
Back to the DAX.
Base Metrics
Total Contestants = DISTINCTCOUNT('dim contestant'[Contestant Name])
Total Episodes = DISTINCTCOUNT('fact Taskmaster'[EpisodeKey])
Total Points = SUM('fact Taskmaster'[Points])
Max Points Scored (ALL Contestant Images) = MAXX(
ALL( 'dim contestant'[Image]),[Total Points])
Points for Group Tasks = CALCULATE(SUM('fact Taskmaster'[Points]),'dim task'[Assignment] = "Group")
Points for Special Tasks = CALCULATE(SUM('fact Taskmaster'[Points]),'dim task'[Assignment] = "Special")
Total Series = CALCULATE(DISTINCTCOUNT('dim episode'[Series]), 'dim episode'[Series] <> "NA")
Total Tasks = DISTINCTCOUNT('fact Taskmaster'[TaskKey])
DAX with variables
Winner + Tiebreaker =
var tiewin = CALCULATE(SUM('fact Taskmaster'[Winner]),FILTER('dim task','dim task'[Task Type] = "Tie Breaker"))
RETURN [Total Points]+tiewin
DAX using If
Group Tasks = IF(CALCULATE(DISTINCTCOUNT('fact Taskmaster'[SeriesStartDateKey]),'dim task'[Assignment] = "Group") = BLANK(), 0,
CALCULATE(DISTINCTCOUNT('fact Taskmaster'[TaskKey]),'dim task'[Assignment] = "Group"))
Special Tasks = IF(CALCULATE(DISTINCTCOUNT('fact Taskmaster'[SeriesStartDateKey]),'dim task'[Assignment] = "Special") = BLANK(), 0,       CALCULATE(DISTINCTCOUNT('fact Taskmaster'[TaskKey]),'dim task'[Assignment] = "Special"))
Tie Breaker = IF( CALCULATE(DISTINCTCOUNT('fact Taskmaster'[TaskKey]),'Dim Task'[Task Type] = "Tie Breaker") = BLANK(), 0, CALCULATE(DISTINCTCOUNT('fact Taskmaster'[TaskKey]),'Dim Task'[Task Type] = "Tie Breaker"))
Tie Breaker episode ? = IF([Tie Breaker]>=1 , "Tie Breaker", "Won on points")
Percentages
% Tasks = [Total Tasks]/ CALCULATE([Total Tasks], ALL('dim task'[Assignment]))*100
% Tasks by Series = [Total Tasks]/ CALCULATE([Total Tasks], ALL('dim episode'[Series]))*100
% Tasks by Type = [Total Tasks]/ CALCULATE([Total Tasks], ALL('dim task'[Task Type]))*100
And each one is added to a display folder. E.g. Measures\Tie Breaker to give us a sub folder under Measures
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-219.png?w=260)
Highlighting Metrics By Colour will be used later in the reporting.
Highlight Max Points Scored (ALL Contestant Images) =
Var MaxPoints = MAXX(
ALL( 'dim contestant'[Image]),[Total Points])
Var Check = IF([Total Points] = MaxPoints, "Light Green","White")
Return Check
Highlight Max Points Scored (ALL Episodes) =
Var MaxPoints = MAXX(
ALL('dim episode'[Episode Name]),[Total Points])
Var Check = IF([Total Points] = MaxPoints, "Light Green","White")
Return Check
Highlight Max Points Scored By Episode =
Var MaxPoints = MAXX(
ALL('dim episode'[Episode Name]), [Total Points])
Var Check = IF([Total Points] = MaxPoints, "Light Green","White")
Return Check
Highlight Min Points Scored (ALL Contestant Images) =
Var MaxPoints = MINX(
ALL('dim contestant'[Image]), [Total Points])
Var Check = IF([Total Points] = MaxPoints, "Light Red","White")
Return Check
Hide original fact data
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-212.png?w=251)
With Everything hidden in the table. we get out fact icon, establishing that this is a fact table
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-214.png?w=148)
Final Updates
Have Thousands separators set for numbers (Measures)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-217.png?w=156)
Make sure percentages are also set correctly
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-220.png?w=168)
![](https://debbiesmspowerbiazureblog.home.blog/wp-content/uploads/2024/05/image-218.png?w=450)
Set Image as Image URL in Properties > Advanced
Our Semantic model is complete. Or at least ready for us to start creating reports.
The other thing to note about this semantic model is there is no need to publish. It autosaves and we simply need to refresh our data source for the reporting to bring through changes.
Lets move on to creating the visuals in the next post.