Power BI “Exercise Analysis” from Apple Health App

📗 Power BI Visualisation from Apple Health App data (XML file)

Link to GitHub to download file “Exercise_Analysis.pbix”

DataSourse: Apple Health App

  • Open the Health app on iPhone.
  • Tap on your profile icon in the top right corner.
  • Scroll down to the bottom of the Health profile and tap on “Export Health Data”
  • Tap on “Export” to confirm that you want to export Health data and start the exporting process, it may take a while to complete.
  • It saves the files in .xml format inside a zip file.

Import XML File to Excel (only Windows)

  • Open the Excel file where you want to get the data from the XML file.
  • Click the Data tab.
  • In the ‘Get & Transform’ data group, click on the ‘Get Data’ option.
  • Go to the ‘From file’ option.
  • Click on ‘From XML’

Data Preparation

  1. From export.xml choose “Workout” data.
  2. Create a Table “Calendar”:
Calendar = CALENDAR(MIN('Workout'[Attribute:creationDate]),MAX('Workout'[Attribute:creationDate]))

Add New columns to “Calendar”:

Weekday = FORMAT('Calendar'[Date],"ddd")

Weekday Number = WEEKDAY('Calendar'[Date])

Week Number = WEEKNUM('Calendar'[Date])
  1. Create a Table “ActivityTypes”:
ActivityTypes = DISTINCT('Workout'[Attribute:workoutActivityType])

Add New column to “ActivityTypes”:

ActivityType = RIGHT('ActivityTypes'[Attribute:workoutActivityType],LEN('ActivityTypes'[Attribute:workoutActivityType])-LEN("HKWorkoutActivityType"))
  1. Add relationships between tables.
image

Create Measures

Average Duration, min = AVERAGEX(Workout,[Total Activity Duration, min])

Average Energy Burned, kcal = AVERAGEX('Workout',[Total Energy Burned, kcal])

Best Daily Activity = MAX('Workout'[Attribute:totalEnergyBurned])

Best Day in Burned kcal = 
VAR Best = MAX('Workout'[Attribute:totalEnergyBurned])
Return CALCULATE(MAX('Workout'[Attribute:creationDate]),'Workout'[Attribute:totalEnergyBurned] = Best)

Distance Walking, km = CALCULATE([Total Distance, km], 'ActivityTypes'[ActivityType]="Walking")

Total Activity Duration, min = SUM(Workout[Attribute:duration])

Total Distance, km = sum('Workout'[Attribute:totalDistance])

Total Distance, km (Cumulative) = CALCULATE([Total Distance, km],FILTER(ALLSELECTED('Calendar'),'Calendar'[Date] <= MAX(Workout[Attribute:creationDate])))

Total Energy Burned, kcal = SUM(Workout[Attribute:totalEnergyBurned])

Walking Distance % of Total = divide(calculate([Total Distance, km],'ActivityTypes'[ActivityType]="Walking"),[Total Distance, km])

Weekly Burned kcal Changes in % = 
VAR CurrentWeek = CALCULATE([Total Energy Burned, kcal],FILTER(ALL('Calendar'[Date]),WEEKNUM('Calendar'[Date]) = SELECTEDVALUE('Calendar'[Week Number])))
VAR PreviousWeek = CALCULATE([Total Energy Burned, kcal], FILTER(ALL('Calendar'[Date]),WEEKNUM('Calendar'[Date]) = SELECTEDVALUE('Calendar'[Week Number]) - 1))
RETURN
DIVIDE((CurrentWeek - PreviousWeek), PreviousWeek)

Data Visualization

image

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.